public class JacksonModule extends Object implements Extension, MessageDecoder, MessageEncoder
{
install(new JacksonModule());
get("/", ctx -> {
MyObject myObject = ...;
// send json
return myObject;
});
post("/", ctx -> {
// read json
MyObject myObject = ctx.body(MyObject.class);
// send json
return myObject;
});
}
For body decoding the client must specify the Content-Type
header set to
application/json
.
You can retrieve the ObjectMapper
via require call:
{
ObjectMapper mapper = require(ObjectMapper.class);
}
Complete documentation is available at: https://jooby.io/modules/jackson.UNSUPPORTED_MEDIA_TYPE
TO_STRING
Constructor and Description |
---|
JacksonModule()
Creates a Jackson module using the default object mapper from
create() . |
JacksonModule(com.fasterxml.jackson.databind.ObjectMapper mapper)
Creates a Jackson module.
|
Modifier and Type | Method and Description |
---|---|
static com.fasterxml.jackson.databind.ObjectMapper |
create()
Default object mapper.
|
Object |
decode(Context ctx,
Type type) |
byte[] |
encode(Context ctx,
Object value) |
void |
install(Jooby application) |
JacksonModule |
module(Class<? extends com.fasterxml.jackson.databind.Module> module)
Add a Jackson module to the object mapper.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
accept
public JacksonModule(@Nonnull com.fasterxml.jackson.databind.ObjectMapper mapper)
mapper
- Object mapper to use.public JacksonModule()
create()
.public JacksonModule module(Class<? extends com.fasterxml.jackson.databind.Module> module)
module
- Module type.public byte[] encode(@Nonnull Context ctx, @Nonnull Object value) throws Exception
encode
in interface MessageEncoder
Exception
public Object decode(Context ctx, Type type) throws Exception
decode
in interface MessageDecoder
Exception
@Nonnull public static final com.fasterxml.jackson.databind.ObjectMapper create()
Jdk8Module
, JavaTimeModule
,
ParameterNamesModule
and AfterburnerModule
.Copyright © 2020. All rights reserved.