Class TomlCodec

java.lang.Object
dev.omnist.codec.TomlCodec

public final class TomlCodec extends Object
Codec for reading and writing the Omnist Document model as TOML (omnist-spec §7.3), built on the tomlj parser.

Reading: TOML tables map to Node values; repeated keys inside an array-of-tables map to repeated edges with the same label. TOML's native date/time/date-time types round-trip directly to their Omnist scalar counterparts.

Writing: always emits inline-table and inline-array syntax rather than [section]/[[section]] headers, sidestepping TOML's header-positional ordering rules. Null-valued leaves cannot be represented in TOML and are dropped, reported via WriteReport.

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 TOML input.
      See Also:
  • Method Details

    • read

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

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

      The schema parameter is intentionally unused here: TOML's own grammar already distinguishes strings/integers/numbers/booleans/temporal values natively, 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 TOML.

      Parameters:
      text - the TOML 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 TOML is syntactically invalid or exceeds MAX_INPUT_LENGTH
    • write

      public static String write(Document node)
      Serializes a Document to TOML text, non-strict (dropping unrepresentable leaves rather than throwing). Equivalent to write(node, false, null).
      Parameters:
      node - the document to serialize; must be a Node
      Returns:
      the TOML text
      Throws:
      WriteException - if node is not a top-level table
    • write

      public static String write(Document node, boolean strict, WriteReport report)
      Serializes a Document to TOML text.
      Parameters:
      node - the document to serialize; must be a Node (TOML requires a top-level table)
      strict - if true, throws when the document contains any adjustment (e.g. a dropped null); if false, applies the adjustment and continues
      report - if non-null, every adjustment made during writing is appended here
      Returns:
      the TOML text
      Throws:
      WriteException - if node is not a top-level table, or 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 TOML text — useful for checking whether a document would round-trip cleanly before committing to a strict write.
      Parameters:
      node - the document to check; non-Node values yield an empty report rather than an error
      Returns:
      the adjustments (e.g. dropped nulls) that a write of node would require