Core (JSON-P)

org.apache.johnzon:johnzon-core:2.2.0

Contents

johnzon-core is the implementation of the JSON-P 2.1 specification: the streaming JsonParser and JsonGenerator, the JsonObject/JsonArray tree model, and JSON Pointer, Patch and Merge Patch support. Since Johnzon 2.0.x it is JSON-P compliant by default.

You will also need the jakarta.json-api dependency, see Getting started.

Factory configuration

JsonGeneratorFactory

The generator factory supports the standard properties (for example pretty printing) plus Johnzon-specific ones:

PropertyTypeEffect
org.apache.johnzon.encodingStringEncoding used when converting an OutputStream to a Writer.
org.apache.johnzon.buffer-strategyStringHow char buffers are obtained. Default is a queue/pool strategy; alternatives are THREAD_LOCAL, BY_INSTANCE (per call, generally slower) and SINGLETON (single instance, no overflow support).
org.apache.johnzon.default-char-buffer-generatorintGenerator buffer size: work in memory and flush less often.
org.apache.johnzon.boundedoutputstreamwriterintBuffer size (if > 0, ±2 characters for encoding logic) when converting an OutputStream to a Writer; enables faster flushing to the underlying stream combined with the generator buffer size.

JSON Pointer and /-

The JSON Pointer specification reserves /- for the add operation, where it points right after the last element of an array. Johnzon’s default implementation extends /- to replace, remove and get as well, where it points at the last element. That makes it easy to work with the tail of an array.

On the 1.x line, strict specification behavior could be enforced with the johnzon-jsonp-strict module, which makes any use of /- other than add fail. Since Johnzon 2.0.x that module no longer exists because johnzon-core is JSON-P compliant by default.

You can also customize the behavior yourself by implementing a JsonPointerFactory and giving it a higher-priority ordinal.