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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum accepted input length in characters, guarding against oversized TOML input. -
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 StringSerializes aDocumentto TOML text, non-strict (dropping unrepresentable leaves rather than throwing).static Stringwrite(Document node, boolean strict, WriteReport report) Serializes aDocumentto TOML text.
-
Field Details
-
MAX_INPUT_LENGTH
public static final int MAX_INPUT_LENGTHMaximum accepted input length in characters, guarding against oversized TOML input.- See Also:
-
-
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 exceedsMAX_INPUT_LENGTH
-
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.