T
- typed class of the POJO for which this JsonCodec servespublic abstract class AbstractJsonCodec<T> extends Object implements JsonCodec<T>
JsonCodec
interface.Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
log |
static com.fasterxml.jackson.databind.ObjectMapper |
mapper
A JSON Mapper used for JSON encoding/decoding.
|
protected static String |
NO_DECODING_SUP |
protected String |
root |
protected String |
roots |
Modifier | Constructor and Description |
---|---|
protected |
AbstractJsonCodec(String root,
String roots) |
Modifier and Type | Method and Description |
---|---|
protected com.fasterxml.jackson.databind.node.ArrayNode |
arrayNode() |
T |
decode(String json)
Decodes the JSON string into a typed POJO.
|
List<T> |
decodeList(String json)
Decodes the JSON string into a typed list of POJO.
|
String |
encode(T pojo,
boolean prettyPrint)
Encodes the given POJO to its JSON string representation.
|
com.fasterxml.jackson.databind.node.ArrayNode |
encodeIterator(Iterator<T> pojos)
Encodes the collection of POJOs to their JSON representation.
|
String |
encodeIterator(Iterator<T> pojos,
boolean prettyPrint)
Encodes the collection of POJOs to their JSON string representation.
|
com.fasterxml.jackson.databind.node.ArrayNode |
encodeList(Collection<T> pojos)
Encodes the collection of POJOs to their JSON representation.
|
String |
encodeList(Collection<T> pojos,
boolean prettyPrint)
Encodes the collection of POJOs to their JSON string representation.
|
protected com.fasterxml.jackson.databind.JsonNode |
fromEnums(Set<? extends Enum<?>> enums) |
protected boolean |
isMissingContent(com.fasterxml.jackson.databind.JsonNode node,
String... keys)
Checks for missing keys in a node.
|
protected static long |
longVal(com.fasterxml.jackson.databind.JsonNode node,
String name) |
protected com.fasterxml.jackson.databind.node.ObjectNode |
objectNode() |
protected com.fasterxml.jackson.databind.JsonNode |
read(String json) |
String |
root()
Returns the root element's singular name.
|
String |
roots()
Returns the root element's plural name.
|
protected <E extends Enum<E>> |
toEnums(com.fasterxml.jackson.databind.node.ArrayNode ar,
Class<E> enumClazz) |
protected String |
write(com.fasterxml.jackson.databind.JsonNode node,
boolean prettyPrint) |
protected static final org.slf4j.Logger log
public static final com.fasterxml.jackson.databind.ObjectMapper mapper
protected static final String NO_DECODING_SUP
protected final String root
protected final String roots
public String root()
JsonCodec
public String roots()
JsonCodec
public String encode(T pojo, boolean prettyPrint)
JsonCodec
public String encodeList(Collection<T> pojos, boolean prettyPrint)
JsonCodec
encodeList
in interface JsonCodec<T>
pojos
- list of POJO's to encodeprettyPrint
- human-readable formatted JSON if true, single-line
JSON otherwisepublic com.fasterxml.jackson.databind.node.ArrayNode encodeList(Collection<T> pojos)
JsonCodec
encodeList
in interface JsonCodec<T>
pojos
- list of POJO's to encodepublic String encodeIterator(Iterator<T> pojos, boolean prettyPrint)
JsonCodec
encodeIterator
in interface JsonCodec<T>
pojos
- iterator over a Collection of POJO's to encodeprettyPrint
- human-readable formatted JSON if true, single-line
JSON otherwisepublic com.fasterxml.jackson.databind.node.ArrayNode encodeIterator(Iterator<T> pojos)
JsonCodec
encodeIterator
in interface JsonCodec<T>
pojos
- iterator over a Collection of POJO's to encodepublic T decode(String json)
JsonCodec
public List<T> decodeList(String json)
JsonCodec
decodeList
in interface JsonCodec<T>
json
- JSON string representation of the typed list of POJOsprotected <E extends Enum<E>> Set<E> toEnums(com.fasterxml.jackson.databind.node.ArrayNode ar, Class<E> enumClazz)
protected String write(com.fasterxml.jackson.databind.JsonNode node, boolean prettyPrint)
protected com.fasterxml.jackson.databind.JsonNode read(String json)
protected boolean isMissingContent(com.fasterxml.jackson.databind.JsonNode node, String... keys)
node
- the JsonNode to be checkedkeys
- key namesprotected com.fasterxml.jackson.databind.node.ObjectNode objectNode()
protected com.fasterxml.jackson.databind.node.ArrayNode arrayNode()
protected static long longVal(com.fasterxml.jackson.databind.JsonNode node, String name)
Copyright © 2015. All Rights Reserved.