Class Materializer

java.lang.Object
dev.omnist.validation.Materializer

public final class Materializer extends Object
Schema-driven coercion of a parsed Document into a fully-typed document (omnist-spec ยง8).

Given a document produced by any codec and a Schema, Materializer walks the document tree and applies type coercions where an exact-type match is not present: integral double values are narrowed to Scalar.IntegerScalar; integer values are widened to Scalar.NumberScalar; and ISO-8601 strings are parsed into the appropriate temporal scalar type. Structural violations (unexpected fields, cardinality mismatches, type mismatches) accumulate as ValidationDiagnostic records and are thrown together as a ValidationException.

This class is stateless; all behavior is via the static materialize(dev.omnist.document.Document, dev.omnist.schema.Schema) entry point.

  • Method Details

    • materialize

      public static Document materialize(Document node, Schema schema)
      Applies schema-driven coercion to node, returning a fully-typed Document.

      The root of node is matched against schema.root() and then recursively against each field's declared type. Structural violations and type mismatches are accumulated and thrown together as a single ValidationException at the end of the walk.

      Parameters:
      node - the document to coerce; typically returned by a codec's read method
      schema - the schema to validate and coerce against
      Returns:
      the coerced document tree; structurally identical to node with scalar values possibly replaced by correctly-typed instances
      Throws:
      ValidationException - if any cardinality, field, or type constraint is violated
      RuntimeException - if nesting depth or node count exceed hard limits (200 / 1,000,000)