public class Jackson extends Object implements Jooby.Module
Parser and Renderer, but also an
ObjectMapper.
{
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;
});
// receiving a json param from a multipart or form url encoded
post("/my-api", req -> {
MyObject obj = req.param("my-object").to(MyObject.class);
return obj;
});
}
If you need a special setting or configuration for your ObjectMapper:
{
use(new Jackson().configure(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 jackson module require some dependencies.| Constructor and Description |
|---|
Jackson()
Creates a new
Jackson module. |
Jackson(com.fasterxml.jackson.databind.ObjectMapper mapper)
Creates a new
Jackson module and use the provided ObjectMapper instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(Env env,
com.typesafe.config.Config config,
com.google.inject.Binder binder) |
Jackson |
doWith(Consumer<com.fasterxml.jackson.databind.ObjectMapper> configurer)
Apply advanced configuration over the provided
ObjectMapper. |
Jackson |
module(Class<? extends com.fasterxml.jackson.databind.Module> module)
Register the provided
Module. |
Jackson |
module(com.fasterxml.jackson.databind.Module module)
Register the provided module.
|
Jackson |
type(MediaType type)
Set the json type supported by this module, default is:
application/json. |
Jackson |
type(String type)
Set the json type supported by this module, default is:
application/json. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigpublic Jackson(com.fasterxml.jackson.databind.ObjectMapper mapper)
Jackson module and use the provided ObjectMapper instance.mapper - ObjectMapper to apply.public Jackson()
Jackson module.public Jackson type(MediaType type)
application/json.type - Media type.public Jackson type(String type)
application/json.type - Media type.public Jackson doWith(Consumer<com.fasterxml.jackson.databind.ObjectMapper> configurer)
ObjectMapper.configurer - A configurer callback.public Jackson module(com.fasterxml.jackson.databind.Module module)
module - A module instance.public Jackson module(Class<? extends com.fasterxml.jackson.databind.Module> module)
Module. The module will be instantiated by Guice.module - Module type.public void configure(Env env, com.typesafe.config.Config config, com.google.inject.Binder binder)
configure in interface Jooby.ModuleCopyright © 2016. All rights reserved.