use of ratpack.jackson.JsonParseOpts in project ratpack by ratpack.
the class JsonParser method parse.
@Override
public <T> T parse(Context context, TypedData body, Parse<T, JsonParseOpts> parse) throws IOException {
if (!body.getContentType().isJson()) {
return null;
}
JsonParseOpts opts = parse.getOpts().orElse(DefaultJsonParseOpts.INSTANCE);
TypeToken<T> type = parse.getType();
ObjectMapper objectMapper = opts.getObjectMapper().orElseGet(() -> context.get(ObjectMapper.class));
InputStream inputStream = body.getInputStream();
if (type.equals(JSON_NODE_TYPE)) {
return cast(objectMapper.readTree(inputStream));
} else {
return objectMapper.readValue(inputStream, toJavaType(type, objectMapper));
}
}
Aggregations