Class JsonCodec
Reading: JSON objects map to Node values; JSON arrays
appearing as object-field values map to repeated edges with the same label; bare top-level
arrays and nested arrays are rejected because they have no labeled-edge representation.
Temporal scalars (Scalar.DateScalar, Scalar.TimeScalar, Scalar.DateTimeScalar) are
written as ISO-8601 strings with an accompanying format.temporal-stringified adjustment.
Writing: Double.NaN and infinite values
are replaced with null and reported as format.float-special errors.
This class is stateless; all methods are static.
-
Method Summary
Modifier and TypeMethodDescriptionstatic WriteReportChecks aDocumentfor JSON-representability issues without serializing it.static DocumentParses JSON 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 JSON 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.static StringSerializes aDocumentto compact JSON with no indentation.static Stringwrite(Document node, Integer indent, boolean strict, WriteReport report) Serializes aDocumentto JSON, optionally indented and in strict mode.
-
Method Details
-
read
Parses JSON text into aDocument.- Parameters:
text- the JSON text; must not benull- Returns:
- the parsed document
- Throws:
RuntimeException- if the JSON is syntactically invalid, or if the root value is an array, or if nesting depth exceeds 200, or if node count exceeds 1,000,000, or if the input is larger thanLimits.DEFAULT_MAX_INPUT_BYTESbytes
-
readWithLimits
Parses JSON 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.An integer literal of more than 10 000 digits (or of more than
maxIntegerDigitswhen that is larger) is refused by the JSON parser itself asparse.codec-syntax.- Parameters:
text- the JSON 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 JSON. Useread(String)followed byMaterializer.materialize(Document, Schema)if schema-driven coercion is required. -
write
Serializes aDocumentto compact JSON with no indentation. Equivalent towrite(node, null, false, null).- Parameters:
node- the document to serialize- Returns:
- the JSON text
- Throws:
WriteException- if the document has structural issues (e.g. non-representable values)
-
write
Serializes aDocumentto JSON, optionally indented and in strict mode.Temporal scalars are written as ISO-8601 strings;
Double.NaNand infinite values are replaced withnulland reported asformat.float-special. Repeated edges with the same label are grouped into a JSON array under that key.- Parameters:
node- the document to serializeindent- if positive, pretty-print with that many spaces;nullor0for compactstrict- iftrue, throws aWriteExceptioninstead of accumulating adjustmentsreport- if non-null, receives all format adjustment records; may benull- Returns:
- the JSON text
- Throws:
WriteException- ifstrictistrueand any adjustment is required
-
check
Checks aDocumentfor JSON-representability issues without serializing it. Returns aWriteReportthat callers can inspect before deciding whether to proceed.- Parameters:
node- the document to check- Returns:
- a report of any format adjustments that would be applied during
write(dev.omnist.document.Document)
-
schemaparameter is ignored for JSON.