Package dev.omnist.codec
Class TomlCodec
java.lang.Object
dev.omnist.codec.TomlCodec
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 TypeMethodDescriptionstatic WriteReportComputes what adjustmentswrite(Document)would make tonodewithout actually producing TOML text — useful for checking whether a document would round-trip cleanly before committing to a strict write.static DocumentParses TOML text into aDocument.static DocumentDeprecated, for removal: This API element is subject to removal in a future version.static DocumentreadWithLimits(String text, Limits limits) Parses TOML text into aDocument, refusing input larger thanLimits.maxInputBytes()bytes (D-23) and honouring the depth, node-count and integer-digit bounds oflimits(D-9, E-4a) with the diagnostics the OML reader gives:document.limit.depthanddocument.limit.nodesat$,document.limit.int-digitsat the Document path of the integer, counting the digits of the value whatever the literal's radix or underscores (D-28).static StringSerializes aDocumentto TOML text, non-strict (dropping unrepresentable leaves rather than throwing).static Stringwrite(Document node, boolean strict, WriteReport report) Serializes aDocumentto TOML text.
-
Method Details
-
read
Parses TOML text into aDocument.- Parameters:
text- the TOML text; must not benull- Returns:
- the parsed document
- Throws:
RuntimeException- if the TOML is syntactically invalid or is larger thanLimits.DEFAULT_MAX_INPUT_BYTESbytes
-
readWithLimits
Parses TOML text into aDocument, refusing input larger thanLimits.maxInputBytes()bytes (D-23) and honouring the depth, node-count and integer-digit bounds oflimits(D-9, E-4a) with the diagnostics the OML reader gives:document.limit.depthanddocument.limit.nodesat$,document.limit.int-digitsat 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 benulllimits- the limits; must not benull- Returns:
- the parsed document
- Throws:
RuntimeException- asread(String), withdocument.limit.input-sizeat$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.Theschemaparameter is ignored for TOML. Useread(String)followed byMaterializer.materialize(Document, Schema)if schema-driven coercion is required. -
write
Serializes aDocumentto TOML text, non-strict (dropping unrepresentable leaves rather than throwing). Equivalent towrite(node, false, null).- Parameters:
node- the document to serialize; must be aNode- Returns:
- the TOML text
- Throws:
WriteException- ifnodeis not a top-level table
-
write
Serializes aDocumentto TOML text.- Parameters:
node- the document to serialize; must be aNode(TOML requires a top-level table)strict- iftrue, throws when the document contains any adjustment (e.g. a dropped null); iffalse, applies the adjustment and continuesreport- if non-null, every adjustment made during writing is appended here- Returns:
- the TOML text
- Throws:
WriteException- ifnodeis not a top-level table, or ifstrictistrueand an adjustment was required
-
check
Computes what adjustmentswrite(Document)would make tonodewithout 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-Nodevalues yield an empty report rather than an error- Returns:
- the adjustments (e.g. dropped nulls) that a write of
nodewould require
-
schemaparameter is ignored for TOML.