Class JsonCodec

java.lang.Object
dev.omnist.codec.JsonCodec

public final class JsonCodec extends Object
Codec for reading and writing the Omnist Document model as JSON (omnist-spec ยง7.3).

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 Details

    • read

      public static Document read(String text)
      Parses JSON text into a Document.
      Parameters:
      text - the JSON text; must not be null
      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 than Limits.DEFAULT_MAX_INPUT_BYTES bytes
    • readWithLimits

      public static Document readWithLimits(String text, Limits limits)
      Parses JSON text into a Document, refusing input larger than Limits.maxInputBytes() bytes (D-23) and honouring the depth, node-count and integer-digit bounds of limits (D-9, E-4a) with the diagnostics the OML reader gives: document.limit.depth and document.limit.nodes at $, document.limit.int-digits at the Document path of the integer.

      An integer literal of more than 10 000 digits (or of more than maxIntegerDigits when that is larger) is refused by the JSON parser itself as parse.codec-syntax.

      Parameters:
      text - the JSON text; must not be null
      limits - the limits; must not be null
      Returns:
      the parsed document
      Throws:
      RuntimeException - as read(String), with document.limit.input-size at $ 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.
      The schema parameter is ignored for JSON. Use read(String) followed by Materializer.materialize(Document, Schema) if schema-driven coercion is required.
    • write

      public static String write(Document node)
      Serializes a Document to compact JSON with no indentation. Equivalent to write(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

      public static String write(Document node, Integer indent, boolean strict, WriteReport report)
      Serializes a Document to JSON, optionally indented and in strict mode.

      Temporal scalars are written as ISO-8601 strings; Double.NaN and infinite values are replaced with null and reported as format.float-special. Repeated edges with the same label are grouped into a JSON array under that key.

      Parameters:
      node - the document to serialize
      indent - if positive, pretty-print with that many spaces; null or 0 for compact
      strict - if true, throws a WriteException instead of accumulating adjustments
      report - if non-null, receives all format adjustment records; may be null
      Returns:
      the JSON text
      Throws:
      WriteException - if strict is true and any adjustment is required
    • check

      public static WriteReport check(Document node)
      Checks a Document for JSON-representability issues without serializing it. Returns a WriteReport that 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)