Class ObjectCodec
java.lang.Object
org.codehaus.jackson.ObjectCodec
- Direct Known Subclasses:
ObjectMapper, ObjectReader
Abstract class that defines the interface that
JsonParser and
JsonGenerator use to serialize and deserialize regular
Java objects (POJOs aka Beans).
The standard implementation of this class is
ObjectMapper.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract JsonNodeMethod for construct root level Array nodes for Tree Model instances.abstract JsonNodeMethod for construct root level Object nodes for Tree Model instances.abstract JsonNodereadTree(JsonParser jp) Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.abstract <T> TreadValue(JsonParser jp, Class<T> valueType) Method to deserialize JSON content into a non-container type (it can be an array type, however): typically a bean, array or a wrapper type (likeBoolean).abstract <T> TreadValue(JsonParser jp, JavaType valueType) Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances.abstract <T> TreadValue(JsonParser jp, TypeReference<?> valueTypeRef) Method to deserialize JSON content into a Java type, reference to which is passed as argument.abstract <T> Iterator<T> readValues(JsonParser jp, Class<T> valueType) Method for reading sequence of Objects from parser stream, all with same specified value type.abstract <T> Iterator<T> readValues(JsonParser jp, JavaType valueType) Method for reading sequence of Objects from parser stream, all with same specified value type.abstract <T> Iterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) Method for reading sequence of Objects from parser stream, all with same specified value type.abstract JsonParserMethod for constructing aJsonParserfor reading contents of a JSON tree, as if it was external serialized JSON content.abstract <T> TtreeToValue(JsonNode n, Class<T> valueType) Convenience method for converting given JSON tree into instance of specified value type.abstract voidwriteTree(JsonGenerator jgen, JsonNode rootNode) Method to serialize given Json Tree, using generator provided.abstract voidwriteValue(JsonGenerator jgen, Object value) Method to serialize given Java Object, using generator provided.
-
Constructor Details
-
ObjectCodec
protected ObjectCodec()
-
-
Method Details
-
readValue
public abstract <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException Method to deserialize JSON content into a non-container type (it can be an array type, however): typically a bean, array or a wrapper type (likeBoolean).Note: this method should NOT be used if the result type is a container (
CollectionorMap. The reason is that due to type erasure, key and value types can not be introspected when using this method.- Throws:
IOExceptionJsonProcessingException
-
readValue
public abstract <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException Method to deserialize JSON content into a Java type, reference to which is passed as argument. Type is passed using so-called "super type token" and specifically needs to be used if the root type is a parameterized (generic) container type.- Throws:
IOExceptionJsonProcessingException
-
readValue
public abstract <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances. Returns root of the resulting tree (where root can consist of just a single node if the current event is a value event, not container).- Throws:
IOExceptionJsonProcessingException
-
readTree
Method to deserialize JSON content as tree expressed using set ofJsonNodeinstances. Returns root of the resulting tree (where root can consist of just a single node if the current event is a value event, not container).- Throws:
IOExceptionJsonProcessingException
-
readValues
public abstract <T> Iterator<T> readValues(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException Method for reading sequence of Objects from parser stream, all with same specified value type.- Throws:
IOExceptionJsonProcessingException- Since:
- 1.9
-
readValues
public abstract <T> Iterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException Method for reading sequence of Objects from parser stream, all with same specified value type.- Throws:
IOExceptionJsonProcessingException- Since:
- 1.9
-
readValues
public abstract <T> Iterator<T> readValues(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException Method for reading sequence of Objects from parser stream, all with same specified value type.- Throws:
IOExceptionJsonProcessingException- Since:
- 1.9
-
writeValue
public abstract void writeValue(JsonGenerator jgen, Object value) throws IOException, JsonProcessingException Method to serialize given Java Object, using generator provided.- Throws:
IOExceptionJsonProcessingException
-
writeTree
public abstract void writeTree(JsonGenerator jgen, JsonNode rootNode) throws IOException, JsonProcessingException Method to serialize given Json Tree, using generator provided.- Throws:
IOExceptionJsonProcessingException
-
createObjectNode
Method for construct root level Object nodes for Tree Model instances.- Since:
- 1.2
-
createArrayNode
Method for construct root level Array nodes for Tree Model instances.- Since:
- 1.2
-
treeAsTokens
Method for constructing aJsonParserfor reading contents of a JSON tree, as if it was external serialized JSON content.- Since:
- 1.3
-
treeToValue
public abstract <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonProcessingException Convenience method for converting given JSON tree into instance of specified value type. This is equivalent to first constructing aJsonParserto iterate over contents of the tree, and using that parser for data binding.- Throws:
IOExceptionJsonProcessingException- Since:
- 1.3
-