Class TomlCodec
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 aDocumentwithout schema guidance.static DocumentParses TOML text into aDocument.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 aDocumentwithout schema guidance. Equivalent toread(text, null).- 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
Parses TOML text into aDocument.The
schemaparameter 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 (unlikeXmlCodec.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 benullschema- 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 exceedsMAX_INPUT_LENGTH
-
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
-