JSON support from the excellent Jackson library.
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-jackson</artifactId>
<version>1.0.0</version>
</dependency>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;
});
}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.