Class JsonValueCodec
java.lang.Object
io.github.protasm.jvmud.compiler.runtime.JsonValueCodec
Converts ordinary JSON documents to and from LPC-compatible data values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringFormats an LPC-compatible value as ordinary JSON.static Objectparse(InputStream input) Parses an ordinary JSON document from a byte stream.static ObjectParses an ordinary JSON document.readArraySlice(InputStream input, String pointer, int offset, int count) Streams a bounded slice from an array selected by an RFC 6901 JSON Pointer.
-
Method Details
-
parse
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 JSONnullbecomes LPC false (0).- Parameters:
document- complete JSON document- Returns:
- LPC-compatible value
- Throws:
IllegalArgumentException- when the document is invalid JSON
-
parse
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
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
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 itpointer- JSON Pointer selecting an array; empty selects a root arrayoffset- zero-based first array entry to returncount- maximum number of entries to return- Returns:
- mutable LPC-compatible array containing at most
countentries - Throws:
IllegalArgumentException- for invalid bounds, JSON, pointer syntax, or a non-array target
-