Apache johnzon

Apache Johnzon is a project providing an implementation of JsonProcessing (aka jsr-353) and a set of useful extension for this specification like an Object mapper and some JAX-RS providers.

Johnzon comes with three main modules.

<dependency>
  <groupId>org.apache.johnzon</groupId>
  <artifactId>johnzon-core</artifactId>
  <version>0.5-incubating</version>
</dependency>

This is the implementation of the specification. You’ll surely want to add the API as dependency too:

<dependency>
  <groupId>org.apache.geronimo.specs</groupId>
  <artifactId>geronimo-json_1.0_spec</artifactId>
  <version>1.0-alpha-1</version>
  <scope>provided</scope> <!-- or compile if your environment doesn't provide it -->
</dependency>
<dependency>
  <groupId>org.apache.johnzon</groupId>
  <artifactId>johnzon-mapper</artifactId>
  <version>0.5-incubating</version>
</dependency>

The mapper module allows you to use the implementation you want of Json Processing specification to map Json to Object and the opposite.

final MySuperObject object = createObject();

final Mapper mapper = new MapperBuilder().build();
mapper.writeObject(object, outputStream);

final MySuperObject otherObject = mapper.readObject(inputStream, MySuperObject.class);
<dependency>
  <groupId>org.apache.johnzon</groupId>
  <artifactId>johnzon-jaxrs</artifactId>
  <version>0.5-incubating</version>
</dependency>

JAX-RS module provides two providers (and underlying MessageBodyReaders and MessageBodyWriters):

  • org.apache.johnzon.jaxrs.JohnzonProvider: use Johnzon Mapper to map Object to Json and the opposite
  • org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider: same as JohnzonProvider but with setters to ease the configuration of the provider in most servers/containers
  • org.apache.johnzon.jaxrs.JsrProvider: allows you to use JsrArray, JsrObject (more generally JsonStructure)

We would like to thank ej-technologies for their Java profiler JProfiler which helped us a lot optimizing memory footprint and speed. JProfiler