JSON support from the excellent Jackson library.
This module provides a JSON body parser and formatter but also an ObjectMapper.
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-jackson</artifactId>
<version>0.12.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());
use((mode, config, binder) -> {
Multibinder.newSetBinder(binder, Module.class).addBinding().to(MyJacksonModuleWiredByGuice.class);
});
}This is useful when your MyJacksonModuleWiredByGuice module require some dependencies.
That's all folks! Enjoy it!!!