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.
Aliases and merge keys are bounded (omnist-spec §2.4.1, D-18 to D-22): the expansion
factor of every mapping and sequence (default 50, document.limit.alias-expansion) and,
for an input that contains an alias or a merge key, the expanded size of the document (default
1 000 000 value slots, document.limit.expanded-size). Both are checked on the composed
node graph before anything is constructed from it; see readWithLimits(String, YamlLimits)
and YamlLimits.
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 aDocument, with the reference alias limits (YamlLimits.DEFAULT).static DocumentDeprecated, for removal: This API element is subject to removal in a future version.static DocumentreadWithLimits(String text, YamlLimits limits) Parses YAML text into aDocument, bounding what its anchors and aliases may expand to (omnist-spec section 2.4.1).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 aDocument, with the reference alias limits (YamlLimits.DEFAULT). Equivalent toreadWithLimits(text, YamlLimits.DEFAULT).- Parameters:
text- the YAML text; must not benull- Returns:
- the parsed document
- Throws:
RuntimeException- if the YAML is syntactically invalid, exceedsMAX_INPUT_LENGTH, or crosses a safety limit (seereadWithLimits(String, YamlLimits))
-
readWithLimits
Parses YAML text into aDocument, bounding what its anchors and aliases may expand to (omnist-spec section 2.4.1).The text is composed into SnakeYAML's node graph, which describes the anchors and aliases without expanding them, and that graph is checked before anything is constructed from it (D-19), in time linear in the input. In this order:
- A merge key whose value is not a mapping or a sequence of mappings is
parse.codec-syntax, and wins over every limit code below (D-18a). - An anchored definition that refers to itself, directly or through other definitions,
is
document.limit.alias-expansion(D-20). - If any mapping or sequence (the root, an inline merge source and an anchored definition
included) has an expansion factor
W / SaboveYamlLimits.maxAliasExpansion(), the input isdocument.limit.alias-expansionat$(D-18). - If the input contains an alias or a merge key and its root materializes more than
YamlLimits.maxExpandedSlots()value slots, the input isdocument.limit.expanded-sizeat$(D-22). An input with neither is exempt however large; one that fails both limits reports step 3.
Wis the structural count of the spec: it ignores key collisions, so a document whose merged keys are overridden can be refused though it materializes fewer slots. A merge of a large block is not free either: a mapping that merges ak-key block and writes one key of its own has an expansion factor of about(k + 2) / 3.- Parameters:
text- the YAML text; must not benulllimits- the alias limits; must not benull- Returns:
- the parsed document
- Throws:
RuntimeException- if the YAML is syntactically invalid, exceedsMAX_INPUT_LENGTH, or crosses a safety limit
- A merge key whose value is not a mapping or a sequence of mappings is
-
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 YAML. Useread(String)followed byMaterializer.materialize(Document, Schema)if schema-driven coercion is required. -
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
-
schemaparameter is ignored for YAML.