org.codehaus.jackson.map
Class ObjectReader

java.lang.Object
  extended by org.codehaus.jackson.map.ObjectReader
All Implemented Interfaces:
Versioned

public class ObjectReader
extends Object
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 by ObjectMapper and can be reused.

Since:
1.6
Author:
tatu

Field Summary
protected  DeserializationConfig _config
          General serialization configuration settings
protected  TypeResolverBuilder<?> _defaultTyper
           
protected  JsonFactory _jsonFactory
          Factory used for constructing JsonGenerators
protected  DeserializerProvider _provider
           
protected  ConcurrentHashMap<JavaType,JsonDeserializer<Object>> _rootDeserializers
          Root-level cached deserializers
protected  SubtypeResolver _subtypeResolver
          Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.
protected  Object _valueToUpdate
          Instance to update with data binding; if any.
protected  JavaType _valueType
          Declared type of value to instantiate during deserialization.
protected  VisibilityChecker<?> _visibilityChecker
           
 
Constructor Summary
protected ObjectReader(ObjectMapper mapper, JavaType valueType, Object valueToUpdate)
          Constructor used by ObjectMapper for initial instantiation
protected ObjectReader(ObjectReader base, DeserializationConfig config, JavaType valueType, Object valueToUpdate)
          Copy constructor used for building variations.
 
Method Summary
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)
           
 JsonNode readTree(InputStream in)
           
 JsonNode readTree(JsonParser jp)
           
 JsonNode readTree(Reader r)
           
 JsonNode readTree(String content)
           
<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(JsonNode src)
          Convenience method for converting results from given JSON tree into given value type.
<T> T
readValue(JsonParser jp)
           
<T> T
readValue(Reader src)
           
<T> T
readValue(String src)
           
<T> T
readValue(URL src)
           
 Version version()
          Method that will return version information stored in and read from jar that contains this class.
 ObjectReader withNodeFactory(JsonNodeFactory f)
           
 ObjectReader withType(Class<?> valueType)
           
 ObjectReader withType(JavaType valueType)
           
 ObjectReader withType(Type valueType)
           
 ObjectReader withValueToUpdate(Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rootDeserializers

protected final ConcurrentHashMap<JavaType,JsonDeserializer<Object>> _rootDeserializers
Root-level cached deserializers


_config

protected final DeserializationConfig _config
General serialization configuration settings


_provider

protected final DeserializerProvider _provider

_jsonFactory

protected final JsonFactory _jsonFactory
Factory used for constructing JsonGenerators


_defaultTyper

protected TypeResolverBuilder<?> _defaultTyper

_visibilityChecker

protected VisibilityChecker<?> _visibilityChecker

_subtypeResolver

protected final SubtypeResolver _subtypeResolver
Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.

Since:
1.6

_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 not ArrayType; array types can not be modified because array size is immutable.

Constructor Detail

ObjectReader

protected ObjectReader(ObjectMapper mapper,
                       JavaType valueType,
                       Object valueToUpdate)
Constructor used by ObjectMapper for initial instantiation


ObjectReader

protected ObjectReader(ObjectReader base,
                       DeserializationConfig config,
                       JavaType valueType,
                       Object valueToUpdate)
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.

Specified by:
version in interface Versioned
Since:
1.6

withType

public ObjectReader withType(JavaType valueType)

withType

public ObjectReader withType(Class<?> valueType)

withType

public ObjectReader withType(Type valueType)

withNodeFactory

public ObjectReader withNodeFactory(JsonNodeFactory f)

withValueToUpdate

public ObjectReader withValueToUpdate(Object value)

readValue

public <T> T readValue(JsonParser jp)
            throws IOException,
                   JsonProcessingException
Throws:
IOException
JsonProcessingException

readTree

public JsonNode readTree(JsonParser jp)
                  throws IOException,
                         JsonProcessingException
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
Since:
1.6

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

_bind

protected Object _bind(JsonParser jp)
                throws IOException,
                       JsonParseException,
                       JsonMappingException
Actual implementation of value reading+binding operation.

Throws:
IOException
JsonParseException
JsonMappingException

_bindAndClose

protected Object _bindAndClose(JsonParser jp)
                        throws IOException,
                               JsonParseException,
                               JsonMappingException
Throws:
IOException
JsonParseException
JsonMappingException

_bindAsTree

protected JsonNode _bindAsTree(JsonParser jp)
                        throws IOException,
                               JsonParseException,
                               JsonMappingException
Throws:
IOException
JsonParseException
JsonMappingException

_bindAndCloseAsTree

protected JsonNode _bindAndCloseAsTree(JsonParser jp)
                                throws IOException,
                                       JsonParseException,
                                       JsonMappingException
Throws:
IOException
JsonParseException
JsonMappingException

_initForReading

protected static JsonToken _initForReading(JsonParser jp)
                                    throws IOException,
                                           JsonParseException,
                                           JsonMappingException
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)