jackson

jackson

JSON support from the excellent Jackson library.

exports

dependency

<dependency>
  <groupId>org.jooby</groupId>
  <artifactId>jooby-jackson</artifactId>
  <version>1.1.0</version>
</dependency>

usage

import org.jooby.json.Jackson;

{
  use(new Jackson());
 
  // sending
  get("/my-api", req -> new MyObject()); 

  // receiving a json body
  post("/my-api", req -> {
    MyObject obj = req.body(MyObject.class);
    return obj;
  });
}

advanced configuration

If you need a special setting or configuration for your ObjectMapper:

{
  use(new Jackson().doWith(mapper -> {
    // setup your custom object mapper
  });
}

or provide an ObjectMapper instance:

{
   ObjectMapper mapper = ....;
   use(new Jackson(mapper));
}

It is possible to wire Jackson modules too:

{
  use(new Jackson()
    .module(MyJacksonModuleWiredByGuice.class)
  );
}

This is useful when your MyJacksonModuleWiredByGuice module require some dependencies.