Datatype module to make Jackson
recognize JsonValue types of JSON API defined in JSR-353 ("JSON-Processing"), so that
you can read JSON as JsonValues and write JsonValues as JSON as part of normal
Jackson processing.
Note that there is also a related jackson-javax-json module which actually implements JSR-353 using Jackson streaming API under the hood.
In both cases the main reason for use is interoperability, as well as to take advantage of powerful data-binding features Jackson provides. Another benefit is the performance: Jackson implementation is often significantly faster for reading and writing JSON content than Oracle's JSR-353 Reference Implementation.
As of 2.3 module is considered stable and production ready.
To use module on Maven-based projects, use following dependency:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr353</artifactId>
<version>2.9.0</version>
</dependency>(or whatever version is most up-to-date at the moment)
Also unless you already include a dependency to a JSR-353 implementation (JDK does not ship with one at least with JDK 8 and prior), you may need to include one. Implementations include:
Reference implementation (last updated in 2013) dependency would be:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>Like all standard Jackson modules (libraries that implement Module interface), registration is done as follows:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JSR353Module());after which functionality is available for all normal Jackson operations:
you can read JSON as JsonValue (or its subtypes), JsonValues as JSON, like:
JsonObject ob = mapper.readValue(JSON, JsonObject.class);
mapper.writeValue(new File("stuff.json"), ob);See Wiki for more information (javadocs, downloads).