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.
-
Field Summary
Fields -
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 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.
-
Field Details
-
MAX_INPUT_LENGTH
public static final int MAX_INPUT_LENGTH- See Also:
-
-
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
-
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.