Class JsonValueCodec

java.lang.Object
io.github.protasm.jvmud.compiler.runtime.JsonValueCodec

public final class JsonValueCodec extends Object
Converts ordinary JSON documents to and from LPC-compatible data values.
  • Method Details

    • parse

      public static Object parse(String document)
      Parses an ordinary JSON document.

      Objects become insertion-ordered mappings with string keys, arrays become mutable LPC arrays, integer-looking numbers remain integral, booleans become 1/0, and JSON null becomes LPC false (0).

      Parameters:
      document - complete JSON document
      Returns:
      LPC-compatible value
      Throws:
      IllegalArgumentException - when the document is invalid JSON
    • parse

      public static Object parse(InputStream input)
      Parses an ordinary JSON document from a byte stream.
      Parameters:
      input - JSON input stream; the Jackson parser closes it
      Returns:
      LPC-compatible value
      Throws:
      IllegalArgumentException - when the document cannot be read as JSON
    • format

      public static String format(Object value)
      Formats an LPC-compatible value as ordinary JSON.

      Mapping keys must be strings. Live objects and other host values are rejected.

      Parameters:
      value - LPC-compatible value
      Returns:
      compact JSON document
      Throws:
      IllegalArgumentException - when the value cannot be represented as ordinary JSON
    • readArraySlice

      public static List<Object> readArraySlice(InputStream input, String pointer, int offset, int count)
      Streams a bounded slice from an array selected by an RFC 6901 JSON Pointer.

      Entries before offset, entries after the requested slice, and unrelated document branches are skipped without being materialized. The parser still scans forward through the file because ordinary JSON has no random-access index.

      Parameters:
      input - JSON input stream; the Jackson parser closes it
      pointer - JSON Pointer selecting an array; empty selects a root array
      offset - zero-based first array entry to return
      count - maximum number of entries to return
      Returns:
      mutable LPC-compatible array containing at most count entries
      Throws:
      IllegalArgumentException - for invalid bounds, JSON, pointer syntax, or a non-array target