public abstract class ObjectCodec extends TreeCodec implements Versioned
JsonParser
and
JsonGenerator
use 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".
Modifier | Constructor and Description |
---|---|
protected |
ObjectCodec() |
Modifier and Type | Method and Description |
---|---|
abstract TreeNode |
createArrayNode()
Method for construct root level Array nodes
for Tree Model instances.
|
abstract TreeNode |
createObjectNode()
Method for construct root level Object nodes
for Tree Model instances.
|
JsonFactory |
getFactory()
Accessor for finding underlying data format factory
(
JsonFactory ) codec will use for data binding. |
JsonFactory |
getJsonFactory()
Deprecated.
Use
getFactory() instead. |
abstract <T extends TreeNode> |
readTree(JsonParser p)
Method for deserializing JSON content as tree expressed
using set of
TreeNode instances. |
abstract <T> T |
readValue(JsonParser p,
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 (like
Boolean ). |
abstract <T> T |
readValue(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 like
Collection and
Map ). |
abstract <T> T |
readValue(JsonParser p,
TypeReference<T> valueTypeRef)
Method to deserialize JSON content into a Java type, reference
to which is passed as argument.
|
abstract <T> Iterator<T> |
readValues(JsonParser p,
Class<T> valueType)
Method for reading sequence of Objects from parser stream,
all with same specified value type.
|
abstract <T> Iterator<T> |
readValues(JsonParser p,
ResolvedType valueType)
Method for reading sequence of Objects from parser stream,
all with same specified value type.
|
abstract <T> Iterator<T> |
readValues(JsonParser p,
TypeReference<T> valueTypeRef)
Method for reading sequence of Objects from parser stream,
all with same specified value type.
|
abstract JsonParser |
treeAsTokens(TreeNode n)
Method for constructing a
JsonParser for reading
contents of a JSON tree, as if it was external serialized
JSON content. |
abstract <T> T |
treeToValue(TreeNode n,
Class<T> valueType)
Convenience method for converting given JSON tree into instance of specified
value type.
|
abstract Version |
version()
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 (see
Version for details). |
abstract void |
writeTree(JsonGenerator gen,
TreeNode tree)
Method for serializing JSON content from given Tree instance, using
specified generator.
|
abstract void |
writeValue(JsonGenerator gen,
Object value)
Method to serialize given Java Object, using generator
provided.
|
missingNode, nullNode
public abstract Version version()
Versioned
Version
for details).public abstract <T> T readValue(JsonParser p, Class<T> valueType) throws IOException
Boolean
).
Note: this method should NOT be used if the result type is a
container (Collection
or Map
.
The reason is that due to type erasure, key and value types
can not be introspected when using this method.
T
- Nominal parameter for target typep
- Parser to use for decoding content to bindvalueType
- Java value type to bind content toIOException
- for low-level read issues, or
JsonParseException
for decoding problemspublic abstract <T> T readValue(JsonParser p, TypeReference<T> valueTypeRef) throws IOException
T
- Nominal parameter for target typep
- Parser to use for decoding content to bindvalueTypeRef
- Java value type to bind content toIOException
- for low-level read issues, or
JsonParseException
for decoding problemspublic abstract <T> T readValue(JsonParser p, ResolvedType valueType) throws IOException
Collection
and
Map
).T
- Nominal parameter for target typep
- Parser to use for decoding content to bindvalueType
- Java value type to bind content toIOException
- for low-level read issues, or
JsonParseException
for decoding problemspublic abstract <T> Iterator<T> readValues(JsonParser p, Class<T> valueType) throws IOException
T
- Nominal parameter for target typep
- Parser to use for decoding content to bindvalueType
- Java value type to bind content toIOException
- for low-level read issues, or
JsonParseException
for decoding problemspublic abstract <T> Iterator<T> readValues(JsonParser p, TypeReference<T> valueTypeRef) throws IOException
T
- Nominal parameter for target typep
- Parser to use for decoding content to bindvalueTypeRef
- Java value type to bind content toIOException
- for low-level read issues, or
JsonParseException
for decoding problemspublic abstract <T> Iterator<T> readValues(JsonParser p, ResolvedType valueType) throws IOException
T
- Nominal parameter for target typep
- Parser to use for decoding content to bindvalueType
- Java value type to bind content toIOException
- for low-level read issues, or
JsonParseException
for decoding problemspublic abstract void writeValue(JsonGenerator gen, Object value) throws IOException
gen
- Generator to use for serializing valuevalue
- Value to serializeIOException
- for low-level write issues, or
JsonGenerationException
for decoding problemspublic abstract <T extends TreeNode> T readTree(JsonParser p) throws IOException
TreeNode
instances. 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.readTree
in class TreeCodec
p
, or null
if empty.IOException
- for low-level read issues, or
JsonParseException
for decoding problemspublic abstract void writeTree(JsonGenerator gen, TreeNode tree) throws IOException
writeTree
in class TreeCodec
gen
- Generator to use for serializing valuetree
- Tree to serializeIOException
- for low-level write issues, or
JsonGenerationException
for decoding problemspublic abstract TreeNode createObjectNode()
createObjectNode
in class TreeCodec
public abstract TreeNode createArrayNode()
createArrayNode
in class TreeCodec
public abstract JsonParser treeAsTokens(TreeNode n)
JsonParser
for reading
contents of a JSON tree, as if it was external serialized
JSON content.treeAsTokens
in class TreeCodec
n
- Content to traverse overpublic abstract <T> T treeToValue(TreeNode n, Class<T> valueType) throws JsonProcessingException
JsonParser
to
iterate over contents of the tree, and using that parser for data binding.T
- Nominal parameter for target typen
- Tree to convertvalueType
- Java target value type to convert content toJsonProcessingException
- if structural conversion fails@Deprecated public JsonFactory getJsonFactory()
getFactory()
instead.JsonFactory
instancepublic JsonFactory getFactory()
JsonFactory
) codec will use for data binding.JsonFactory
instanceCopyright © 2021 JBoss by Red Hat. All rights reserved.