Class YamlCodec
Reading: YAML mappings map to Node values;
SnakeYAML's default core-schema resolution handles booleans (including YAML 1.1
words like yes/no/on/off) with no customization
needed. Timestamps are custom-resolved to distinguish a bare date from a full
date-time before falling back to SnakeYAML's own timestamp construction.
Writing: cannot achieve round-trip fidelity for time-kind
scalars — no safe bare YAML spelling exists for a time-of-day that doesn't
collide with YAML's sexagesimal (base-60) number notation — so time
values are written as quoted ISO-8601 strings via the usual
format.temporal-stringified adjustment.
This class is stateless; all methods are static.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum accepted input length in characters, guarding against oversized YAML input. -
Method Summary
Modifier and TypeMethodDescriptionstatic WriteReportComputes what adjustmentswrite(Document)would make tonodewithout actually producing YAML text.static DocumentParses YAML text into aDocumentwithout schema guidance.static DocumentParses YAML text into aDocument.static StringSerializes aDocumentto YAML text, non-strict (applying adjustments rather than throwing).static Stringwrite(Document node, boolean strict, WriteReport report) Serializes aDocumentto YAML text.
-
Field Details
-
MAX_INPUT_LENGTH
public static final int MAX_INPUT_LENGTHMaximum accepted input length in characters, guarding against oversized YAML input.- See Also:
-
-
Method Details
-
read
Parses YAML text into aDocumentwithout schema guidance. Equivalent toread(text, null).- Parameters:
text- the YAML text; must not benull- Returns:
- the parsed document
- Throws:
RuntimeException- if the YAML is syntactically invalid or exceedsMAX_INPUT_LENGTH
-
read
Parses YAML text into aDocument.The
schemaparameter is intentionally unused here: YAML's own grammar already distinguishes strings/integers/numbers/booleans/temporal values natively (via its resolvers), 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 YAML.- Parameters:
text- the YAML 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 YAML is syntactically invalid or exceedsMAX_INPUT_LENGTH
-
write
Serializes aDocumentto YAML text, non-strict (applying adjustments rather than throwing). Equivalent towrite(node, false, null).- Parameters:
node- the document to serialize- Returns:
- the YAML text
-
write
Serializes aDocumentto YAML text.- Parameters:
node- the document to serializestrict- iftrue, throws when the document contains any adjustment (e.g. a stringified time value); iffalse, applies the adjustment and continuesreport- if non-null, every adjustment made during writing is appended here- Returns:
- the YAML text
- Throws:
WriteException- ifstrictistrueand an adjustment was required
-
check
Computes what adjustmentswrite(Document)would make tonodewithout actually producing YAML text.- Parameters:
node- the document to check- Returns:
- the adjustments (e.g. stringified time values) that a write of
nodewould require
-