Package com.fasterxml.jackson.core
Class ObjectCodec
- java.lang.Object
 - 
- com.fasterxml.jackson.core.TreeCodec
 - 
- com.fasterxml.jackson.core.ObjectCodec
 
 
 
- 
- All Implemented Interfaces:
 Versioned
- Direct Known Subclasses:
 ObjectMapper,ObjectReader
public abstract class ObjectCodec extends TreeCodec implements Versioned
Abstract class that defines the interface thatJsonParserandJsonGeneratoruse to serialize and deserialize regular Java objects (POJOs aka Beans).The standard implementation of this class is
com.fasterxml.jackson.databind.ObjectMapper, defined in the "jackson-databind". 
- 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract TreeNodecreateArrayNode()Method for construct root level Array nodes for Tree Model instances.abstract TreeNodecreateObjectNode()Method for construct root level Object nodes for Tree Model instances.JsonFactorygetFactory()Accessor for finding underlying data format factory (JsonFactory) codec will use for data binding.JsonFactorygetJsonFactory()Deprecated.UsegetFactory()instead.abstract <T extends TreeNode>
TreadTree(JsonParser p)Method for deserializing JSON content as tree expressed using set ofTreeNodeinstances.abstract <T> TreadValue(JsonParser p, ResolvedType valueType)Method to deserialize JSON content into a POJO, type specified with fully resolved type object (so it can be a generic type, including containers likeCollectionandMap).abstract <T> TreadValue(JsonParser p, TypeReference<T> valueTypeRef)Method to deserialize JSON content into a Java type, reference to which is passed as argument.abstract <T> TreadValue(JsonParser p, java.lang.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> java.util.Iterator<T>readValues(JsonParser p, ResolvedType valueType)Method for reading sequence of Objects from parser stream, all with same specified value type.abstract <T> java.util.Iterator<T>readValues(JsonParser p, TypeReference<T> valueTypeRef)Method for reading sequence of Objects from parser stream, all with same specified value type.abstract <T> java.util.Iterator<T>readValues(JsonParser p, java.lang.Class<T> valueType)Method for reading sequence of Objects from parser stream, all with same specified value type.abstract JsonParsertreeAsTokens(TreeNode n)Method for constructing aJsonParserfor reading contents of a JSON tree, as if it was external serialized JSON content.abstract <T> TtreeToValue(TreeNode n, java.lang.Class<T> valueType)Convenience method for converting given JSON tree into instance of specified value type.abstract Versionversion()Method called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersionfor details).abstract voidwriteTree(JsonGenerator gen, TreeNode tree)Method for serializing JSON content from given Tree instance, using specified generator.abstract voidwriteValue(JsonGenerator gen, java.lang.Object value)Method to serialize given Java Object, using generator provided.- 
Methods inherited from class com.fasterxml.jackson.core.TreeCodec
missingNode, nullNode 
 - 
 
 - 
 
- 
- 
Method Detail
- 
version
public abstract Version version()
Description copied from interface:VersionedMethod called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersionfor details). 
- 
readValue
public abstract <T> T readValue(JsonParser p, java.lang.Class<T> valueType) throws java.io.IOException
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.- Type Parameters:
 T- Nominal parameter for target type- Parameters:
 p- Parser to use for decoding content to bindvalueType- Java value type to bind content to- Returns:
 - Value deserialized
 - Throws:
 java.io.IOException- for low-level read issues, orJsonParseExceptionfor decoding problems
 
- 
readValue
public abstract <T> T readValue(JsonParser p, TypeReference<T> valueTypeRef) throws java.io.IOException
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.- Type Parameters:
 T- Nominal parameter for target type- Parameters:
 p- Parser to use for decoding content to bindvalueTypeRef- Java value type to bind content to- Returns:
 - Value deserialized
 - Throws:
 java.io.IOException- for low-level read issues, orJsonParseExceptionfor decoding problems
 
- 
readValue
public abstract <T> T readValue(JsonParser p, ResolvedType valueType) throws java.io.IOException
Method to deserialize JSON content into a POJO, type specified with fully resolved type object (so it can be a generic type, including containers likeCollectionandMap).- Type Parameters:
 T- Nominal parameter for target type- Parameters:
 p- Parser to use for decoding content to bindvalueType- Java value type to bind content to- Returns:
 - Value deserialized
 - Throws:
 java.io.IOException- for low-level read issues, orJsonParseExceptionfor decoding problems
 
- 
readValues
public abstract <T> java.util.Iterator<T> readValues(JsonParser p, java.lang.Class<T> valueType) throws java.io.IOException
Method for reading sequence of Objects from parser stream, all with same specified value type.- Type Parameters:
 T- Nominal parameter for target type- Parameters:
 p- Parser to use for decoding content to bindvalueType- Java value type to bind content to- Returns:
 - Iterator for incrementally deserializing values
 - Throws:
 java.io.IOException- for low-level read issues, orJsonParseExceptionfor decoding problems
 
- 
readValues
public abstract <T> java.util.Iterator<T> readValues(JsonParser p, TypeReference<T> valueTypeRef) throws java.io.IOException
Method for reading sequence of Objects from parser stream, all with same specified value type.- Type Parameters:
 T- Nominal parameter for target type- Parameters:
 p- Parser to use for decoding content to bindvalueTypeRef- Java value type to bind content to- Returns:
 - Iterator for incrementally deserializing values
 - Throws:
 java.io.IOException- for low-level read issues, orJsonParseExceptionfor decoding problems
 
- 
readValues
public abstract <T> java.util.Iterator<T> readValues(JsonParser p, ResolvedType valueType) throws java.io.IOException
Method for reading sequence of Objects from parser stream, all with same specified value type.- Type Parameters:
 T- Nominal parameter for target type- Parameters:
 p- Parser to use for decoding content to bindvalueType- Java value type to bind content to- Returns:
 - Iterator for incrementally deserializing values
 - Throws:
 java.io.IOException- for low-level read issues, orJsonParseExceptionfor decoding problems
 
- 
writeValue
public abstract void writeValue(JsonGenerator gen, java.lang.Object value) throws java.io.IOException
Method to serialize given Java Object, using generator provided.- Parameters:
 gen- Generator to use for serializing valuevalue- Value to serialize- Throws:
 java.io.IOException- for low-level write issues, orJsonGenerationExceptionfor decoding problems
 
- 
readTree
public abstract <T extends TreeNode> T readTree(JsonParser p) throws java.io.IOException
Method for deserializing JSON content as tree expressed using set ofTreeNodeinstances. 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). Empty or whitespace documents return null.- Specified by:
 readTreein classTreeCodec- Returns:
 - next tree from 
p, ornullif empty. - Throws:
 java.io.IOException- for low-level read issues, orJsonParseExceptionfor decoding problems
 
- 
writeTree
public abstract void writeTree(JsonGenerator gen, TreeNode tree) throws java.io.IOException
Method for serializing JSON content from given Tree instance, using specified generator.- Specified by:
 writeTreein classTreeCodec- Parameters:
 gen- Generator to use for serializing valuetree- Tree to serialize- Throws:
 java.io.IOException- for low-level write issues, orJsonGenerationExceptionfor decoding problems
 
- 
createObjectNode
public abstract TreeNode createObjectNode()
Method for construct root level Object nodes for Tree Model instances.- Specified by:
 createObjectNodein classTreeCodec- Returns:
 - Object node created
 
 
- 
createArrayNode
public abstract TreeNode createArrayNode()
Method for construct root level Array nodes for Tree Model instances.- Specified by:
 createArrayNodein classTreeCodec- Returns:
 - Array node created
 
 
- 
treeAsTokens
public abstract JsonParser treeAsTokens(TreeNode n)
Method for constructing aJsonParserfor reading contents of a JSON tree, as if it was external serialized JSON content.- Specified by:
 treeAsTokensin classTreeCodec- Parameters:
 n- Content to traverse over- Returns:
 - Parser constructed for traversing over contents of specified node
 
 
- 
treeToValue
public abstract <T> T treeToValue(TreeNode n, java.lang.Class<T> valueType) throws 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.- Type Parameters:
 T- Nominal parameter for target type- Parameters:
 n- Tree to convertvalueType- Java target value type to convert content to- Returns:
 - Converted value instance
 - Throws:
 JsonProcessingException- if structural conversion fails
 
- 
getJsonFactory
@Deprecated public JsonFactory getJsonFactory()
Deprecated.UsegetFactory()instead.- Returns:
 - Underlying 
JsonFactoryinstance 
 
- 
getFactory
public JsonFactory getFactory()
Accessor for finding underlying data format factory (JsonFactory) codec will use for data binding.- Returns:
 - Underlying 
JsonFactoryinstance 
 
 - 
 
 -