Class YamlCodec

java.lang.Object
dev.omnist.codec.YamlCodec

public final class YamlCodec extends Object
Codec for reading and writing the Omnist Document model as YAML (omnist-spec §7.3), built on SnakeYAML.

Reading: YAML mappings map to Node values; SnakeYAML's default core-schema resolution handles booleans (including YAML 1.1 words like yes/no/on/off) with no customization needed. Timestamps are custom-resolved to distinguish a bare date from a full date-time before falling back to SnakeYAML's own timestamp construction.

Writing: cannot achieve round-trip fidelity for time-kind scalars — no safe bare YAML spelling exists for a time-of-day that doesn't collide with YAML's sexagesimal (base-60) number notation — so time values are written as quoted ISO-8601 strings via the usual format.temporal-stringified adjustment.

This class is stateless; all methods are static.

  • Field Details

    • MAX_INPUT_LENGTH

      public static final int MAX_INPUT_LENGTH
      Maximum accepted input length in characters, guarding against oversized YAML input.
      See Also:
  • Method Details

    • read

      public static Document read(String text)
      Parses YAML text into a Document without schema guidance. Equivalent to read(text, null).
      Parameters:
      text - the YAML text; must not be null
      Returns:
      the parsed document
      Throws:
      RuntimeException - if the YAML is syntactically invalid or exceeds MAX_INPUT_LENGTH
    • read

      public static Document read(String text, Schema schema)
      Parses YAML text into a Document.

      The schema parameter is intentionally unused here: YAML's own grammar already distinguishes strings/integers/numbers/booleans/temporal values natively (via its resolvers), so there is no scalar-kind ambiguity for a schema to resolve (unlike XmlCodec.read(String, dev.omnist.schema.Schema), where every value is a string until schema-guided pre-typing runs). The parameter exists only so callers can invoke every format codec through the same two-argument shape without special-casing YAML.

      Parameters:
      text - the YAML text; must not be null
      schema - accepted for call-site symmetry with the other format codecs; has no effect
      Returns:
      the parsed document
      Throws:
      RuntimeException - if the YAML is syntactically invalid or exceeds MAX_INPUT_LENGTH
    • write

      public static String write(Document node)
      Serializes a Document to YAML text, non-strict (applying adjustments rather than throwing). Equivalent to write(node, false, null).
      Parameters:
      node - the document to serialize
      Returns:
      the YAML text
    • write

      public static String write(Document node, boolean strict, WriteReport report)
      Serializes a Document to YAML text.
      Parameters:
      node - the document to serialize
      strict - if true, throws when the document contains any adjustment (e.g. a stringified time value); if false, applies the adjustment and continues
      report - if non-null, every adjustment made during writing is appended here
      Returns:
      the YAML text
      Throws:
      WriteException - if strict is true and an adjustment was required
    • check

      public static WriteReport check(Document node)
      Computes what adjustments write(Document) would make to node without actually producing YAML text.
      Parameters:
      node - the document to check
      Returns:
      the adjustments (e.g. stringified time values) that a write of node would require