Class ObjectReader
- All Implemented Interfaces:
Versioned
ObjectMapper
and can be
reused.- Since:
- 1.6
- Author:
- tatu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DeserializationConfig
General serialization configuration settings; while immutable, can use copy-constructor to create modified instances as necessary.protected final InjectableValues
Values that can be injected during deserialization, if any.protected final JsonFactory
Factory used for constructingJsonGenerator
sprotected final DeserializerProvider
protected final ConcurrentHashMap
<JavaType, JsonDeserializer<Object>> Root-level cached deserializersprotected final FormatSchema
When using data format that uses a schema, schema is passed to parser.protected final boolean
Flag that indicates whether root values are expected to be unwrapped or notprotected final Object
Instance to update with data binding; if any.protected final JavaType
Declared type of value to instantiate during deserialization. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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
Modifier and TypeMethodDescriptionprotected Object
_bind
(JsonParser jp) Actual implementation of value reading+binding operation.protected Object
protected JsonNode
protected JsonNode
protected DeserializationContext
protected JsonDeserializer
<Object> _findRootDeserializer
(DeserializationConfig cfg, JavaType valueType) Method called to locate deserializer for the passed root-level value.protected static JsonToken
protected Object
_unwrapAndDeserialize
(JsonParser jp, DeserializationContext ctxt, JavaType rootType, JsonDeserializer<Object> deser) Method for construct root level Array nodes for Tree Model instances.Method for construct root level Object nodes for Tree Model instances.readTree
(InputStream in) Method that reads content from given input source, using configuration of this reader, and binds it as JSON Tree.Method that reads content from given input source, using configuration of this reader, and binds it as JSON Tree.Method that reads content from given JSON input String, using configuration of this reader, and binds it as JSON Tree.readTree
(JsonParser jp) Convenience method that binds content read using given parser, using configuration of this reader, except that content is bound as JSON tree instead of configured root value type.<T> T
readValue
(byte[] src) Method that binds content read from given byte array, using configuration of this reader.<T> T
readValue
(byte[] src, int offset, int length) Method that binds content read from given byte array, using configuration of this reader.<T> T
<T> T
readValue
(InputStream src) Method that binds content read from given input source, using configuration of this reader.<T> T
Method that binds content read from given input source, using configuration of this reader.<T> T
Method that binds content read from given JSON string, using configuration of this reader.<T> T
Method that binds content read from given input source, using configuration of this reader.<T> T
Convenience method for converting results from given JSON tree into given value type.<T> T
readValue
(JsonParser jp) Method that binds content read using given parser, using configuration of this reader, including expected result type.<T> T
readValue
(JsonParser jp, Class<T> valueType) Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type).<T> T
readValue
(JsonParser jp, JavaType valueType) Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type).<T> T
readValue
(JsonParser jp, TypeReference<?> valueTypeRef) Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type).final <T> MappingIterator
<T> readValues
(byte[] src) Since 1.9.3<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) Convenience method that is equivalent to:<T> Iterator
<T> readValues
(JsonParser jp, JavaType valueType) Convenience method that is equivalent to:<T> Iterator
<T> readValues
(JsonParser jp, TypeReference<?> valueTypeRef) Convenience method that is equivalent to: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()
Method that will return version information stored in and read from jar that contains this class.withInjectableValues
(InjectableValues injectableValues) Method for constructing a new instance with configuration that uses passedInjectableValues
to provide injectable values.Method for constructing a new reader instance with configuration that uses passedJsonNodeFactory
for constructingJsonNode
instances.withSchema
(FormatSchema schema) Method for constructing a new instance with configuration that passes specifiedFormatSchema
toJsonParser
that is constructed for parsing content.Method for constructing a new reader instance that is configured to data bind into specified type.Method for constructing a new reader instance that is configured to data bind into specified type.Method for constructing a new reader instance that is configured to data bind into specified type.withType
(TypeReference<?> valueTypeRef) Method for constructing a new reader instance that is configured to data bind into specified type.withValueToUpdate
(Object value) Method for constructing a new instance with configuration that updates passed Object (as root value), instead of constructing a new 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 Details
-
_config
General serialization configuration settings; while immutable, can use copy-constructor to create modified instances as necessary. -
_unwrapRoot
protected final boolean _unwrapRootFlag that indicates whether root values are expected to be unwrapped or not- Since:
- 1.9
-
_rootDeserializers
Root-level cached deserializers -
_provider
-
_jsonFactory
Factory used for constructingJsonGenerator
s -
_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
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
When using data format that uses a schema, schema is passed to parser.- Since:
- 1.8
-
_injectableValues
Values that can be injected during deserialization, if any.- Since:
- 1.9
-
-
Constructor Details
-
ObjectReader
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 Details
-
version
Method that will return version information stored in and read from jar that contains this class. -
withType
Method for constructing a new reader instance that is configured to data bind into specified type.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
withType
Method for constructing a new reader instance that is configured to data bind into specified type.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
withType
Method for constructing a new reader instance that is configured to data bind into specified type.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
withType
Method for constructing a new reader instance that is configured to data bind into specified type.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Since:
- 1.8
-
withNodeFactory
Method for constructing a new reader instance with configuration that uses passedJsonNodeFactory
for constructingJsonNode
instances.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
withValueToUpdate
Method for constructing a new instance with configuration that updates passed Object (as root value), instead of constructing a new value.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
withSchema
Method for constructing a new instance with configuration that passes specifiedFormatSchema
toJsonParser
that is constructed for parsing content.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Since:
- 1.8
-
withInjectableValues
Method for constructing a new instance with configuration that uses passedInjectableValues
to provide injectable values.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Since:
- 1.9
-
readValue
Method that binds content read using given parser, using configuration of this reader, including expected result type. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type). Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type). Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type). Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Specified by:
readValue
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readTree
Convenience method that binds content read using given parser, using configuration of this reader, except that content is bound as JSON tree instead of configured root value type.Note: if an object was specified with
withValueToUpdate(java.lang.Object)
, it will be ignored.- Specified by:
readTree
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> Iterator<T> readValues(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException Convenience method that is equivalent to:withType(valueType).readValues(jp);
- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> Iterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException Convenience method that is equivalent to:withType(valueTypeRef).readValues(jp);
- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValues
public <T> Iterator<T> readValues(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException Convenience method that is equivalent to:withType(valueType).readValues(jp);
- Specified by:
readValues
in classObjectCodec
- Throws:
IOException
JsonProcessingException
-
readValue
Method that binds content read from given input source, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Throws:
IOException
JsonProcessingException
-
readValue
Method that binds content read from given input source, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Throws:
IOException
JsonProcessingException
-
readValue
Method that binds content read from given JSON string, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Throws:
IOException
JsonProcessingException
-
readValue
Method that binds content read from given byte array, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Throws:
IOException
JsonProcessingException
-
readValue
public <T> T readValue(byte[] src, int offset, int length) throws IOException, JsonProcessingException Method that binds content read from given byte array, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Throws:
IOException
JsonProcessingException
-
readValue
- Throws:
IOException
JsonProcessingException
-
readValue
Method that binds content read from given input source, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object)
.- Throws:
IOException
JsonProcessingException
-
readValue
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
Method that reads content from given input source, using configuration of this reader, and binds it as JSON Tree.Note that if an object was specified with a call to
withValueToUpdate(Object)
it will just be ignored; result is always a newly constructedJsonNode
instance.- Throws:
IOException
JsonProcessingException
-
readTree
Method that reads content from given input source, using configuration of this reader, and binds it as JSON Tree.Note that if an object was specified with a call to
withValueToUpdate(Object)
it will just be ignored; result is always a newly constructedJsonNode
instance.- Throws:
IOException
JsonProcessingException
-
readTree
Method that reads content from given JSON input String, using configuration of this reader, and binds it as JSON Tree.Note that if an object was specified with a call to
withValueToUpdate(Object)
it will just be ignored; result is always a newly constructedJsonNode
instance.- Throws:
IOException
JsonProcessingException
-
readValues
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
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
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 final <T> MappingIterator<T> readValues(byte[] src) throws IOException, JsonProcessingException Since 1.9.3- Throws:
IOException
JsonProcessingException
-
readValues
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
readValues
Method for reading sequence of Objects from parser stream.- Throws:
IOException
JsonProcessingException
- Since:
- 1.8
-
_bind
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
Description copied from class:ObjectCodec
Method for construct root level Array nodes for Tree Model instances.- Specified by:
createArrayNode
in classObjectCodec
-
createObjectNode
Description copied from class:ObjectCodec
Method for construct root level Object nodes for Tree Model instances.- Specified by:
createObjectNode
in classObjectCodec
-
treeAsTokens
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
-