Package org.codehaus.jackson.map
Class ObjectReader
- java.lang.Object
-
- org.codehaus.jackson.ObjectCodec
-
- org.codehaus.jackson.map.ObjectReader
-
- All Implemented Interfaces:
Versioned
public class ObjectReader extends ObjectCodec implements Versioned
Builder object that can be used for per-serialization configuration of deserialization parameters, such as root type to use or object to update (instead of constructing new instance). Uses "fluid" (aka builder) pattern so that instances are immutable (and thus fully thread-safe with no external synchronization); new instances are constructed for different configurations. Instances are initially constructed byObjectMapper
and can be reused.- Since:
- 1.6
- Author:
- tatu
-
-
Field Summary
Fields Modifier and Type Field Description protected DeserializationConfig
_config
General serialization configuration settings; while immutable, can use copy-constructor to create modified instances as necessary.protected InjectableValues
_injectableValues
Values that can be injected during deserialization, if any.protected JsonFactory
_jsonFactory
Factory used for constructingJsonGenerator
sprotected DeserializerProvider
_provider
protected ConcurrentHashMap<JavaType,JsonDeserializer<Object>>
_rootDeserializers
Root-level cached deserializersprotected FormatSchema
_schema
When using data format that uses a schema, schema is passed to parser.protected boolean
_unwrapRoot
Flag that indicates whether root values are expected to be unwrapped or notprotected Object
_valueToUpdate
Instance to update with data binding; if any.protected JavaType
_valueType
Declared type of value to instantiate during deserialization.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ObjectReader(ObjectMapper mapper, DeserializationConfig config)
Constructor used byObjectMapper
for initial instantiationprotected
ObjectReader(ObjectMapper mapper, DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues)
protected
ObjectReader(ObjectReader base, DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues)
Copy constructor used for building variations.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
_bind(JsonParser jp)
Actual implementation of value reading+binding operation.protected Object
_bindAndClose(JsonParser jp)
protected JsonNode
_bindAndCloseAsTree(JsonParser jp)
protected JsonNode
_bindAsTree(JsonParser jp)
protected DeserializationContext
_createDeserializationContext(JsonParser jp, DeserializationConfig cfg)
protected JsonDeserializer<Object>
_findRootDeserializer(DeserializationConfig cfg, JavaType valueType)
Method called to locate deserializer for the passed root-level value.protected static JsonToken
_initForReading(JsonParser jp)
protected Object
_unwrapAndDeserialize(JsonParser jp, DeserializationContext ctxt, JavaType rootType, JsonDeserializer<Object> deser)
JsonNode
createArrayNode()
Method for construct root level Array nodes for Tree Model instances.JsonNode
createObjectNode()
Method for construct root level Object nodes for Tree Model instances.JsonNode
readTree(InputStream in)
JsonNode
readTree(Reader r)
JsonNode
readTree(String content)
JsonNode
readTree(JsonParser jp)
Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.<T> T
readValue(byte[] src)
<T> T
readValue(byte[] src, int offset, int length)
<T> T
readValue(File src)
<T> T
readValue(InputStream src)
<T> T
readValue(Reader src)
<T> T
readValue(String src)
<T> T
readValue(URL src)
<T> T
readValue(JsonNode src)
Convenience method for converting results from given JSON tree into given value type.<T> T
readValue(JsonParser jp)
<T> T
readValue(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
).<T> T
readValue(JsonParser jp, JavaType valueType)
Method to deserialize JSON content as tree expressed using set ofJsonNode
instances.<T> T
readValue(JsonParser jp, TypeReference<?> valueTypeRef)
Method to deserialize JSON content into a Java type, reference to which is passed as argument.<T> MappingIterator<T>
readValues(byte[] src, int offset, int length)
Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues(File src)
Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues(InputStream src)
Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues(Reader src)
Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues(String json)
Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues(URL src)
Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>
readValues(JsonParser jp)
Method for reading sequence of Objects from parser stream.<T> Iterator<T>
readValues(JsonParser jp, Class<T> valueType)
Method for reading sequence of Objects from parser stream, all with same specified value type.<T> Iterator<T>
readValues(JsonParser jp, JavaType valueType)
Method for reading sequence of Objects from parser stream, all with same specified value type.<T> Iterator<T>
readValues(JsonParser jp, TypeReference<?> valueTypeRef)
Method for reading sequence of Objects from parser stream, all with same specified value type.JsonParser
treeAsTokens(JsonNode n)
Method for constructing aJsonParser
for reading contents of a JSON tree, as if it was external serialized JSON content.<T> T
treeToValue(JsonNode n, Class<T> valueType)
Convenience method for converting given JSON tree into instance of specified value type.Version
version()
Method that will return version information stored in and read from jar that contains this class.ObjectReader
withInjectableValues(InjectableValues injectableValues)
ObjectReader
withNodeFactory(JsonNodeFactory f)
ObjectReader
withSchema(FormatSchema schema)
ObjectReader
withType(Class<?> valueType)
ObjectReader
withType(Type valueType)
ObjectReader
withType(JavaType valueType)
ObjectReader
withType(TypeReference<?> valueTypeRef)
ObjectReader
withValueToUpdate(Object value)
void
writeTree(JsonGenerator jgen, JsonNode rootNode)
NOTE: NOT implemented forObjectReader
.void
writeValue(JsonGenerator jgen, Object value)
Method to serialize given Java Object, using generator provided.
-
-
-
Field Detail
-
_config
protected final DeserializationConfig _config
General serialization configuration settings; while immutable, can use copy-constructor to create modified instances as necessary.
-
_unwrapRoot
protected final boolean _unwrapRoot
Flag that indicates whether root values are expected to be unwrapped or not- Since:
- 1.9
-
_rootDeserializers
protected final ConcurrentHashMap<JavaType,JsonDeserializer<Object>> _rootDeserializers
Root-level cached deserializers
-
_provider
protected final DeserializerProvider _provider
-
_jsonFactory
protected final JsonFactory _jsonFactory
Factory used for constructingJsonGenerator
s
-
_valueType
protected final JavaType _valueType
Declared type of value to instantiate during deserialization. Defines which deserializer to use; as well as base type of instance to construct if an updatable value is not configured to be used (subject to changes by embedded type information, for polymorphic types). If_valueToUpdate
is non-null, only used for locating deserializer.
-
_valueToUpdate
protected final Object _valueToUpdate
Instance to update with data binding; if any. If null, a new instance is created, if non-null, properties of this value object will be updated instead. Note that value can be of almost any type, except notArrayType
; array types can not be modified because array size is immutable.
-
_schema
protected final FormatSchema _schema
When using data format that uses a schema, schema is passed to parser.- Since:
- 1.8
-
_injectableValues
protected final InjectableValues _injectableValues
Values that can be injected during deserialization, if any.- Since:
- 1.9
-
-
Constructor Detail
-
ObjectReader
protected ObjectReader(ObjectMapper mapper, DeserializationConfig config)
Constructor used byObjectMapper
for initial instantiation- Since:
- 1.8
-
ObjectReader
protected ObjectReader(ObjectMapper mapper, DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues)
-
ObjectReader
protected ObjectReader(ObjectReader base, DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues)
Copy constructor used for building variations.
-
-
Method Detail
-
version
public Version version()
Method that will return version information stored in and read from jar that contains this class.
-
withType
public ObjectReader withType(JavaType valueType)
-
withType
public ObjectReader withType(Class<?> valueType)
-
withType
public ObjectReader withType(Type valueType)
-
withType
public ObjectReader withType(TypeReference<?> valueTypeRef)
- Since:
- 1.8
-
withNodeFactory
public ObjectReader withNodeFactory(JsonNodeFactory f)
-
withValueToUpdate
public ObjectReader withValueToUpdate(Object value)
-
withSchema
public ObjectReader withSchema(FormatSchema schema)
- Since:
- 1.8
-
withInjectableValues
public ObjectReader withInjectableValues(InjectableValues injectableValues)
- Since:
- 1.9
-
readValue
public <T> T readValue(JsonParser jp) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
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 (
Collection
orMap
. The reason is that due to type erasure, key and value types can not be introspected when using this method.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
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.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
Method to deserialize JSON content as tree expressed using set ofJsonNode
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).- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readTree
public JsonNode readTree(JsonParser jp) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
Method to deserialize JSON content as tree expressed using set ofJsonNode
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).- Specified by:
readTree
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> Iterator<T> readValues(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
Method for reading sequence of Objects from parser stream, all with same specified value type.- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> Iterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
Method for reading sequence of Objects from parser stream, all with same specified value type.- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> Iterator<T> readValues(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
Method for reading sequence of Objects from parser stream, all with same specified value type.- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(InputStream src) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(Reader src) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(String src) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(byte[] src) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(byte[] src, int offset, int length) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(File src) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(URL src) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(JsonNode src) throws IOException, JsonProcessingException
Convenience method for converting results from given JSON tree into given value type. Basically short-cut for:objectReader.readValue(src.traverse())
- Throws:
IOException
JsonProcessingException
-
readTree
public JsonNode readTree(InputStream in) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readTree
public JsonNode readTree(Reader r) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readTree
public JsonNode readTree(String content) throws IOException, JsonProcessingException
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> MappingIterator<T> readValues(JsonParser jp) throws IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(InputStream src) throws IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(Reader src) throws IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(String json) throws IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(byte[] src, int offset, int length) throws IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(File src) throws IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
public <T> MappingIterator<T> readValues(URL src) throws IOException, JsonProcessingException
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
_bind
protected Object _bind(JsonParser jp) throws IOException, JsonParseException, JsonMappingException
Actual implementation of value reading+binding operation.
-
_bindAndClose
protected Object _bindAndClose(JsonParser jp) throws IOException, JsonParseException, JsonMappingException
-
_bindAsTree
protected JsonNode _bindAsTree(JsonParser jp) throws IOException, JsonParseException, JsonMappingException
-
_bindAndCloseAsTree
protected JsonNode _bindAndCloseAsTree(JsonParser jp) throws IOException, JsonParseException, JsonMappingException
-
_initForReading
protected static JsonToken _initForReading(JsonParser jp) throws IOException, JsonParseException, JsonMappingException
-
_findRootDeserializer
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationConfig cfg, JavaType valueType) throws JsonMappingException
Method called to locate deserializer for the passed root-level value.- Throws:
JsonMappingException
-
_createDeserializationContext
protected DeserializationContext _createDeserializationContext(JsonParser jp, DeserializationConfig cfg)
-
_unwrapAndDeserialize
protected Object _unwrapAndDeserialize(JsonParser jp, DeserializationContext ctxt, JavaType rootType, JsonDeserializer<Object> deser) throws IOException, JsonParseException, JsonMappingException
-
createArrayNode
public JsonNode createArrayNode()
Description copied from class:ObjectCodec
Method for construct root level Array nodes for Tree Model instances.- Specified by:
createArrayNode
in classObjectCodec
-
createObjectNode
public JsonNode createObjectNode()
Description copied from class:ObjectCodec
Method for construct root level Object nodes for Tree Model instances.- Specified by:
createObjectNode
in classObjectCodec
-
treeAsTokens
public JsonParser treeAsTokens(JsonNode n)
Description copied from class:ObjectCodec
Method for constructing aJsonParser
for reading contents of a JSON tree, as if it was external serialized JSON content.- Specified by:
treeAsTokens
in classObjectCodec
-
treeToValue
public <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
Convenience method for converting given JSON tree into instance of specified value type. This is equivalent to first constructing aJsonParser
to iterate over contents of the tree, and using that parser for data binding.- Specified by:
treeToValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
writeTree
public void writeTree(JsonGenerator jgen, JsonNode rootNode) throws IOException, JsonProcessingException
NOTE: NOT implemented forObjectReader
.- Specified by:
writeTree
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
writeValue
public void writeValue(JsonGenerator jgen, Object value) throws IOException, JsonProcessingException
Description copied from class:ObjectCodec
Method to serialize given Java Object, using generator provided.- Specified by:
writeValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
-