public abstract class Jackson
extends java.lang.Object
The JacksonModule
Guice module provides the infrastructure necessary to use these functions.
The methods that return a JsonRender
are to be used with the Context.render(Object)
method for serializing
objects to the response as JSON.
import ratpack.handling.Handler; import ratpack.handling.Context; import static ratpack.jackson.Jackson.json; public class MyHandler implements Handler { public void handle(Context context) { Person person = new Person("John"); context.render(json(person)); } } public class Person { private final String name; public Person(String name) { this.name = name; } }
The methods that return a JsonParseOpts
are to be used with the Context.parse(ratpack.parse.Parse)
method for deserializing
request bodies containing JSON.
import ratpack.handling.Handler; import ratpack.handling.Context; import com.fasterxml.jackson.databind.JsonNode; import static ratpack.jackson.Jackson.jsonNode; public class MyHandler implements Handler { public void handle(Context context) { JsonNode node = context.parse(jsonNode()) context.render(node.get("someKey")); } }
Constructor and Description |
---|
Jackson() |
Modifier and Type | Method and Description |
---|---|
static <T> ratpack.parse.Parse<T,JsonParseOpts> |
fromJson(java.lang.Class<T> type) |
static <T> ratpack.parse.Parse<T,JsonParseOpts> |
fromJson(java.lang.Class<T> type,
ObjectMapper objectMapper) |
static <T> ratpack.parse.Parse<T,JsonParseOpts> |
fromJson(com.google.common.reflect.TypeToken<T> type) |
static <T> ratpack.parse.Parse<T,JsonParseOpts> |
fromJson(com.google.common.reflect.TypeToken<T> type,
ObjectMapper objectMapper) |
static JsonRender |
json(java.lang.Object object)
Jackson rendering of the given object, using the default object writer.
|
static JsonRender |
json(java.lang.Object object,
ObjectWriter objectWriter)
Jackson rendering of the given object, using the given object writer.
|
static ratpack.parse.Parse<JsonNode,JsonParseOpts> |
jsonNode() |
static ratpack.parse.Parse<JsonNode,JsonParseOpts> |
jsonNode(ObjectMapper objectMapper) |
public static JsonRender json(java.lang.Object object)
object
- The object to render as JSON.public static JsonRender json(java.lang.Object object, @Nullable ObjectWriter objectWriter)
object
- The object to render as JSON.objectWriter
- The writer to use to render the object as JSON. If null, the default object writer will be used by the renderer.public static ratpack.parse.Parse<JsonNode,JsonParseOpts> jsonNode()
public static ratpack.parse.Parse<JsonNode,JsonParseOpts> jsonNode(@Nullable ObjectMapper objectMapper)
public static <T> ratpack.parse.Parse<T,JsonParseOpts> fromJson(java.lang.Class<T> type)
public static <T> ratpack.parse.Parse<T,JsonParseOpts> fromJson(com.google.common.reflect.TypeToken<T> type)
public static <T> ratpack.parse.Parse<T,JsonParseOpts> fromJson(java.lang.Class<T> type, @Nullable ObjectMapper objectMapper)
public static <T> ratpack.parse.Parse<T,JsonParseOpts> fromJson(com.google.common.reflect.TypeToken<T> type, @Nullable ObjectMapper objectMapper)