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 aDocumentwithout schema guidance.static DocumentParses JSON text into aDocument.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 aDocumentwithout schema guidance. Equivalent toread(text, null).- Parameters:
text- the JSON text; must not benull- Returns:
- the parsed document
- Throws:
RuntimeException- if the JSON is syntactically invalid or structurally unsupported
-
read
Parses JSON text into aDocument.The
schemaparameter is intentionally unused here: JSON's own grammar already distinguishes strings/numbers/booleans natively, so there is no scalar-kind ambiguity for a schema to resolve at parse time (unlikeXmlCodec.read(String, dev.omnist.schema.Schema), where every value is a string until schema-guided pre-typing runs). Schema-driven coercion of an already-typed value (e.g. a JSON string into a schema'sdatefield) is a separate concern handled by a laterMaterializercall, not by this method.- Parameters:
text- the JSON 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 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
-
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)
-