public abstract class Jackson extends 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> Parse<T,JsonParseOpts> |
fromJson(Class<T> type) |
static <T> Parse<T,JsonParseOpts> |
fromJson(Class<T> type,
ObjectMapper objectMapper) |
static <T> Parse<T,JsonParseOpts> |
fromJson(com.google.common.reflect.TypeToken<T> type) |
static <T> Parse<T,JsonParseOpts> |
fromJson(com.google.common.reflect.TypeToken<T> type,
ObjectMapper objectMapper) |
static <T> JsonRender<T> |
json(T object)
Jackson rendering of the given object, using the default object writer.
|
static <T> JsonRender<T> |
json(T object,
ObjectWriter objectWriter)
Jackson rendering of the given object, using the given object writer.
|
static Parse<JsonNode,JsonParseOpts> |
jsonNode() |
static Parse<JsonNode,JsonParseOpts> |
jsonNode(ObjectMapper objectMapper) |
public static <T> JsonRender<T> json(T object)
T - The type of the object to render as JSON.object - The object to render as JSON.public static <T> JsonRender<T> json(T object, @Nullable ObjectWriter objectWriter)
T - The type of the object to render as JSON.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 Parse<JsonNode,JsonParseOpts> jsonNode()
public static Parse<JsonNode,JsonParseOpts> jsonNode(@Nullable ObjectMapper objectMapper)
public static <T> Parse<T,JsonParseOpts> fromJson(Class<T> type)
public static <T> Parse<T,JsonParseOpts> fromJson(com.google.common.reflect.TypeToken<T> type)
public static <T> Parse<T,JsonParseOpts> fromJson(Class<T> type, @Nullable ObjectMapper objectMapper)
public static <T> Parse<T,JsonParseOpts> fromJson(com.google.common.reflect.TypeToken<T> type, @Nullable ObjectMapper objectMapper)