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.

  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static Document
    read(String text)
    Parses TOML text into a Document.
    static Document
    read(String text, Schema schema)
    Deprecated, for removal: This API element is subject to removal in a future version.
    The schema parameter is ignored for TOML.
    static Document
    readWithLimits(String text, Limits limits)
    Parses TOML text into a Document, refusing input larger than Limits.maxInputBytes() bytes (D-23) and honouring the depth, node-count and integer-digit bounds of limits (D-9, E-4a) with the diagnostics the OML reader gives: document.limit.depth and document.limit.nodes at $, document.limit.int-digits at the Document path of the integer, counting the digits of the value whatever the literal's radix or underscores (D-28).
    static String
    Serializes a Document to TOML text, non-strict (dropping unrepresentable leaves rather than throwing).
    static String
    write(Document node, boolean strict, WriteReport report)
    Serializes a Document to TOML text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • read

      public static Document read(String text)
      Parses TOML text into a Document.
      Parameters:
      text - the TOML text; must not be null
      Returns:
      the parsed document
      Throws:
      RuntimeException - if the TOML is syntactically invalid or is larger than Limits.DEFAULT_MAX_INPUT_BYTES bytes
    • readWithLimits

      public static Document readWithLimits(String text, Limits limits)
      Parses TOML text into a Document, refusing input larger than Limits.maxInputBytes() bytes (D-23) and honouring the depth, node-count and integer-digit bounds of limits (D-9, E-4a) with the diagnostics the OML reader gives: document.limit.depth and document.limit.nodes at $, document.limit.int-digits at the Document path of the integer, counting the digits of the value whatever the literal's radix or underscores (D-28).
      Parameters:
      text - the TOML text; must not be null
      limits - the limits; must not be null
      Returns:
      the parsed document
      Throws:
      RuntimeException - as read(String), with document.limit.input-size at $ for an input over the maximum
    • read

      @Deprecated(since="0.1.0-alpha", forRemoval=true) public static Document read(String text, Schema schema)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The schema parameter is ignored for TOML. Use read(String) followed by Materializer.materialize(Document, Schema) if schema-driven coercion is required.
    • 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