org.codehaus.jackson.map.deser
Class BeanDeserializer

java.lang.Object
  extended by org.codehaus.jackson.map.JsonDeserializer<T>
      extended by org.codehaus.jackson.map.deser.StdDeserializer<Object>
          extended by org.codehaus.jackson.map.deser.BeanDeserializer
All Implemented Interfaces:
ResolvableDeserializer
Direct Known Subclasses:
ThrowableDeserializer

public class BeanDeserializer
extends StdDeserializer<Object>
implements ResolvableDeserializer

Deserializer class that can deserialize instances of arbitrary bean objects, usually from JSON Object structs, but possibly also from simple types like String values.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.codehaus.jackson.map.deser.StdDeserializer
StdDeserializer.AtomicBooleanDeserializer, StdDeserializer.AtomicReferenceDeserializer, StdDeserializer.BigDecimalDeserializer, StdDeserializer.BigIntegerDeserializer, StdDeserializer.BooleanDeserializer, StdDeserializer.ByteDeserializer, StdDeserializer.CalendarDeserializer, StdDeserializer.CharacterDeserializer, StdDeserializer.ClassDeserializer, StdDeserializer.DoubleDeserializer, StdDeserializer.FloatDeserializer, StdDeserializer.IntegerDeserializer, StdDeserializer.LongDeserializer, StdDeserializer.NumberDeserializer, StdDeserializer.PrimitiveOrWrapperDeserializer<T>, StdDeserializer.ShortDeserializer, StdDeserializer.SqlDateDeserializer, StdDeserializer.StackTraceElementDeserializer, StdDeserializer.StringDeserializer, StdDeserializer.TokenBufferDeserializer
 
Nested classes/interfaces inherited from class org.codehaus.jackson.map.JsonDeserializer
JsonDeserializer.None
 
Field Summary
protected  SettableAnyProperty _anySetter
          Fallback setter used for handling any properties that are not mapped to regular setters.
protected  Map<String,SettableBeanProperty> _backRefs
          We may also have one or more back reference fields (usually zero or one).
protected  BeanPropertyMap _beanProperties
          Mapping of property names to properties, built when all properties to use have been succesfully resolved.
protected  JavaType _beanType
          Declared type of the bean this deserializer handles.
protected  Constructor<?> _defaultConstructor
          Default constructor used to instantiate the bean when mapping from Json object, and only using setters for initialization (not specific constructors).
protected  org.codehaus.jackson.map.deser.Creator.Delegating _delegatingCreator
          If the bean class can be instantiated using a creator (an annotated single arg constructor or static method), this object is used for handling details of how delegate-based deserialization and instance construction works
protected  AnnotatedClass _forClass
          Class for which deserializer is built; used for accessing annotations during resolution phase (see resolve(org.codehaus.jackson.map.DeserializationConfig, org.codehaus.jackson.map.DeserializerProvider)).
protected  HashSet<String> _ignorableProps
          In addition to properties that are set, we will also keep track of recognized but ignorable properties: these will be skipped without errors or warnings.
protected  boolean _ignoreAllUnknown
          Flag that can be set to ignore and skip unknown properties.
protected  org.codehaus.jackson.map.deser.Creator.NumberBased _numberCreator
          If the "bean" class can be instantiated using just a single numeric (int, long) value (via constructor, static method etc), this object knows how to invoke method/constructor in question.
protected  BeanProperty _property
          Property that contains value to be deserialized using deserializer
protected  org.codehaus.jackson.map.deser.Creator.PropertyBased _propertyBasedCreator
          If the bean needs to be instantiated using constructor or factory method that takes one or more named properties as argument(s), this creator is used for instantiation.
protected  org.codehaus.jackson.map.deser.Creator.StringBased _stringCreator
          If the "bean" class can be instantiated using just a single String (via constructor, static method etc), this object knows how to invoke method/constructor in question.
protected  HashMap<ClassKey,JsonDeserializer<Object>> _subDeserializers
          Lazily constructed map used to contain deserializers needed for polymorphic subtypes.
 
Fields inherited from class org.codehaus.jackson.map.deser.StdDeserializer
_valueClass
 
Constructor Summary
  BeanDeserializer(AnnotatedClass forClass, JavaType type, BeanProperty property, CreatorContainer creators, BeanPropertyMap properties, Map<String,SettableBeanProperty> backRefs, HashSet<String> ignorableProps, boolean ignoreAllUnknown, SettableAnyProperty anySetter)
           
protected BeanDeserializer(BeanDeserializer src)
          Copy-constructor that can be used by sub-classes to allow copy-on-write styling copying of settings of an existing instance.
 
Method Summary
protected  Object _deserializeUsingPropertyBased(JsonParser jp, DeserializationContext ctxt)
          Method called to deserialize bean using "property-based creator": this means that a non-default constructor or factory method is called, and then possibly other setters.
protected  JsonDeserializer<Object> _findSubclassDeserializer(DeserializationContext ctxt, Object bean, TokenBuffer unknownTokens)
          Helper method called to (try to) locate deserializer for given sub-type of type that this deserializer handles.
protected  Object constructDefaultInstance()
          Method that is called to instantiate Object of type this deserializer produces, using the default (no-argument) constructor.
 Object deserialize(JsonParser jp, DeserializationContext ctxt)
          Main deserialization method for bean-based objects (POJOs).
 Object deserialize(JsonParser jp, DeserializationContext ctxt, Object bean)
          Secondary deserialization method, called in cases where POJO instance is created as part of deserialization, potentially after collecting some or all of the properties to set.
 Object deserializeFromNumber(JsonParser jp, DeserializationContext ctxt)
           
 Object deserializeFromObject(JsonParser jp, DeserializationContext ctxt)
           
 Object deserializeFromString(JsonParser jp, DeserializationContext ctxt)
           
 Object deserializeUsingCreator(JsonParser jp, DeserializationContext ctxt)
           
 Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer)
          Base implementation that does not assume specific type inclusion mechanism.
 SettableBeanProperty findBackReference(String logicalName)
          Method needed by BeanDeserializerFactory to properly link managed- and back-reference pairs.
 Class<?> getBeanClass()
           
 int getPropertyCount()
          Accessor for checking number of deserialized properties.
 JavaType getValueType()
          Exact structured type deserializer handles, if known.
protected  Object handlePolymorphic(JsonParser jp, DeserializationContext ctxt, Object bean, TokenBuffer unknownTokens)
          Method called in cases where we may have polymorphic deserialization case: that is, type of Creator-constructed bean is not the type of deserializer itself.
protected  Object handleUnknownProperties(DeserializationContext ctxt, Object bean, TokenBuffer unknownTokens)
          Method called to handle set of one or more unknown properties, stored in their entirety in given TokenBuffer (as field entries, name and value).
protected  void handleUnknownProperty(JsonParser jp, DeserializationContext ctxt, Object beanOrClass, String propName)
          Method called when a JSON property is encountered that has not matching setter, any-setter or field, and thus can not be assigned.
 boolean hasProperty(String propertyName)
           
 Iterator<SettableBeanProperty> properties()
           
 void resolve(DeserializationConfig config, DeserializerProvider provider)
          Method called to finalize setup of this deserializer, after deserializer itself has been registered.
 void wrapAndThrow(Throwable t, Object bean, int index)
          Deprecated. Since 1.7 use variant that takes DeserializationContext
 void wrapAndThrow(Throwable t, Object bean, int index, DeserializationContext ctxt)
           
 void wrapAndThrow(Throwable t, Object bean, String fieldName)
          Deprecated. Since 1.7 use variant that takes DeserializationContext
 void wrapAndThrow(Throwable t, Object bean, String fieldName, DeserializationContext ctxt)
          Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype of IOException, or an unchecked exception.
protected  void wrapInstantiationProblem(Throwable t, DeserializationContext ctxt)
           
 
Methods inherited from class org.codehaus.jackson.map.deser.StdDeserializer
_parseBoolean, _parseBooleanPrimitive, _parseDate, _parseDouble, _parseDoublePrimitive, _parseFloat, _parseFloatPrimitive, _parseInteger, _parseIntPrimitive, _parseLong, _parseLongPrimitive, _parseShort, _parseShortPrimitive, findDeserializer, getValueClass, isDefaultSerializer, parseDouble, reportUnknownProperty
 
Methods inherited from class org.codehaus.jackson.map.JsonDeserializer
getNullValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_forClass

protected final AnnotatedClass _forClass
Class for which deserializer is built; used for accessing annotations during resolution phase (see resolve(org.codehaus.jackson.map.DeserializationConfig, org.codehaus.jackson.map.DeserializerProvider)).


_beanType

protected final JavaType _beanType
Declared type of the bean this deserializer handles.


_property

protected final BeanProperty _property
Property that contains value to be deserialized using deserializer

Since:
1.7

_defaultConstructor

protected final Constructor<?> _defaultConstructor
Default constructor used to instantiate the bean when mapping from Json object, and only using setters for initialization (not specific constructors).

Note: may be null, if deserializer is constructed for abstract types (which is only useful if additional type information will allow construction of concrete subtype).


_stringCreator

protected final org.codehaus.jackson.map.deser.Creator.StringBased _stringCreator
If the "bean" class can be instantiated using just a single String (via constructor, static method etc), this object knows how to invoke method/constructor in question. If so, no setters will be used.


_numberCreator

protected final org.codehaus.jackson.map.deser.Creator.NumberBased _numberCreator
If the "bean" class can be instantiated using just a single numeric (int, long) value (via constructor, static method etc), this object knows how to invoke method/constructor in question. If so, no setters will be used.


_delegatingCreator

protected final org.codehaus.jackson.map.deser.Creator.Delegating _delegatingCreator
If the bean class can be instantiated using a creator (an annotated single arg constructor or static method), this object is used for handling details of how delegate-based deserialization and instance construction works


_propertyBasedCreator

protected final org.codehaus.jackson.map.deser.Creator.PropertyBased _propertyBasedCreator
If the bean needs to be instantiated using constructor or factory method that takes one or more named properties as argument(s), this creator is used for instantiation.


_beanProperties

protected final BeanPropertyMap _beanProperties
Mapping of property names to properties, built when all properties to use have been succesfully resolved.

Since:
1.7

_anySetter

protected final SettableAnyProperty _anySetter
Fallback setter used for handling any properties that are not mapped to regular setters. If setter is not null, it will be called once for each such property.


_ignorableProps

protected final HashSet<String> _ignorableProps
In addition to properties that are set, we will also keep track of recognized but ignorable properties: these will be skipped without errors or warnings.


_ignoreAllUnknown

protected final boolean _ignoreAllUnknown
Flag that can be set to ignore and skip unknown properties. If set, will not throw an exception for unknown properties.


_backRefs

protected final Map<String,SettableBeanProperty> _backRefs
We may also have one or more back reference fields (usually zero or one).


_subDeserializers

protected HashMap<ClassKey,JsonDeserializer<Object>> _subDeserializers
Lazily constructed map used to contain deserializers needed for polymorphic subtypes.

Constructor Detail

BeanDeserializer

public BeanDeserializer(AnnotatedClass forClass,
                        JavaType type,
                        BeanProperty property,
                        CreatorContainer creators,
                        BeanPropertyMap properties,
                        Map<String,SettableBeanProperty> backRefs,
                        HashSet<String> ignorableProps,
                        boolean ignoreAllUnknown,
                        SettableAnyProperty anySetter)

BeanDeserializer

protected BeanDeserializer(BeanDeserializer src)
Copy-constructor that can be used by sub-classes to allow copy-on-write styling copying of settings of an existing instance.

Since:
1.7
Method Detail

hasProperty

public boolean hasProperty(String propertyName)

getPropertyCount

public int getPropertyCount()
Accessor for checking number of deserialized properties.

Since:
1.7

resolve

public void resolve(DeserializationConfig config,
                    DeserializerProvider provider)
             throws JsonMappingException
Method called to finalize setup of this deserializer, after deserializer itself has been registered. This is needed to handle recursive and transitive dependencies.

Specified by:
resolve in interface ResolvableDeserializer
provider - Provider that has constructed deserializer this method is called on.
Throws:
JsonMappingException

deserialize

public final Object deserialize(JsonParser jp,
                                DeserializationContext ctxt)
                         throws IOException,
                                JsonProcessingException
Main deserialization method for bean-based objects (POJOs).

Specified by:
deserialize in class JsonDeserializer<Object>
Parameters:
jp - Parsed used for reading Json content
ctxt - Context that can be used to access information about this deserialization activity.
Returns:
Deserializer value
Throws:
IOException
JsonProcessingException

deserialize

public Object deserialize(JsonParser jp,
                          DeserializationContext ctxt,
                          Object bean)
                   throws IOException,
                          JsonProcessingException
Secondary deserialization method, called in cases where POJO instance is created as part of deserialization, potentially after collecting some or all of the properties to set.

Overrides:
deserialize in class JsonDeserializer<Object>
Throws:
IOException
JsonProcessingException

deserializeWithType

public Object deserializeWithType(JsonParser jp,
                                  DeserializationContext ctxt,
                                  TypeDeserializer typeDeserializer)
                           throws IOException,
                                  JsonProcessingException
Description copied from class: StdDeserializer
Base implementation that does not assume specific type inclusion mechanism. Sub-classes are expected to override this method if they are to handle type information.

Overrides:
deserializeWithType in class StdDeserializer<Object>
typeDeserializer - Deserializer to use for handling type information
Throws:
IOException
JsonProcessingException

getBeanClass

public final Class<?> getBeanClass()

getValueType

public JavaType getValueType()
Description copied from class: StdDeserializer
Exact structured type deserializer handles, if known.

Default implementation just returns null.

Overrides:
getValueType in class StdDeserializer<Object>

properties

public Iterator<SettableBeanProperty> properties()
Since:
1.6

findBackReference

public SettableBeanProperty findBackReference(String logicalName)
Method needed by BeanDeserializerFactory to properly link managed- and back-reference pairs.


deserializeFromObject

public Object deserializeFromObject(JsonParser jp,
                                    DeserializationContext ctxt)
                             throws IOException,
                                    JsonProcessingException
Throws:
IOException
JsonProcessingException

deserializeFromString

public Object deserializeFromString(JsonParser jp,
                                    DeserializationContext ctxt)
                             throws IOException,
                                    JsonProcessingException
Throws:
IOException
JsonProcessingException

deserializeFromNumber

public Object deserializeFromNumber(JsonParser jp,
                                    DeserializationContext ctxt)
                             throws IOException,
                                    JsonProcessingException
Throws:
IOException
JsonProcessingException

deserializeUsingCreator

public Object deserializeUsingCreator(JsonParser jp,
                                      DeserializationContext ctxt)
                               throws IOException,
                                      JsonProcessingException
Throws:
IOException
JsonProcessingException

_deserializeUsingPropertyBased

protected final Object _deserializeUsingPropertyBased(JsonParser jp,
                                                      DeserializationContext ctxt)
                                               throws IOException,
                                                      JsonProcessingException
Method called to deserialize bean using "property-based creator": this means that a non-default constructor or factory method is called, and then possibly other setters. The trick is that values for creator method need to be buffered, first; and due to non-guaranteed ordering possibly some other properties as well.

Throws:
IOException
JsonProcessingException
Since:
1.2

handleUnknownProperty

protected void handleUnknownProperty(JsonParser jp,
                                     DeserializationContext ctxt,
                                     Object beanOrClass,
                                     String propName)
                              throws IOException,
                                     JsonProcessingException
Method called when a JSON property is encountered that has not matching setter, any-setter or field, and thus can not be assigned.

Overrides:
handleUnknownProperty in class StdDeserializer<Object>
Parameters:
jp - Parser that points to value of the unknown property
ctxt - Context for deserialization; allows access to the parser, error reporting functionality
beanOrClass - Instance that is being populated by this deserializer, or if not known, Class that would be instantiated. If null, will assume type is what StdDeserializer.getValueClass() returns.
propName - Name of the property that can not be mapped
Throws:
IOException
JsonProcessingException

handleUnknownProperties

protected Object handleUnknownProperties(DeserializationContext ctxt,
                                         Object bean,
                                         TokenBuffer unknownTokens)
                                  throws IOException,
                                         JsonProcessingException
Method called to handle set of one or more unknown properties, stored in their entirety in given TokenBuffer (as field entries, name and value).

Throws:
IOException
JsonProcessingException

handlePolymorphic

protected Object handlePolymorphic(JsonParser jp,
                                   DeserializationContext ctxt,
                                   Object bean,
                                   TokenBuffer unknownTokens)
                            throws IOException,
                                   JsonProcessingException
Method called in cases where we may have polymorphic deserialization case: that is, type of Creator-constructed bean is not the type of deserializer itself. It should be a sub-class or implementation class; either way, we may have more specific deserializer to use for handling it.

Parameters:
jp - (optional) If not null, parser that has more properties to handle (in addition to buffered properties); if null, all properties are passed in buffer
Throws:
IOException
JsonProcessingException

_findSubclassDeserializer

protected JsonDeserializer<Object> _findSubclassDeserializer(DeserializationContext ctxt,
                                                             Object bean,
                                                             TokenBuffer unknownTokens)
                                                      throws IOException,
                                                             JsonProcessingException
Helper method called to (try to) locate deserializer for given sub-type of type that this deserializer handles.

Throws:
IOException
JsonProcessingException

constructDefaultInstance

protected Object constructDefaultInstance()
Method that is called to instantiate Object of type this deserializer produces, using the default (no-argument) constructor.

Returns:
Instance of type this deserializer handles
Since:
1.7

wrapAndThrow

public void wrapAndThrow(Throwable t,
                         Object bean,
                         String fieldName,
                         DeserializationContext ctxt)
                  throws IOException
Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype of IOException, or an unchecked exception.

Rules for wrapping and unwrapping are bit complicated; essentially:

Throws:
IOException

wrapAndThrow

public void wrapAndThrow(Throwable t,
                         Object bean,
                         int index,
                         DeserializationContext ctxt)
                  throws IOException
Throws:
IOException

wrapInstantiationProblem

protected void wrapInstantiationProblem(Throwable t,
                                        DeserializationContext ctxt)
                                 throws IOException
Throws:
IOException

wrapAndThrow

@Deprecated
public void wrapAndThrow(Throwable t,
                                    Object bean,
                                    String fieldName)
                  throws IOException
Deprecated. Since 1.7 use variant that takes DeserializationContext

Throws:
IOException

wrapAndThrow

@Deprecated
public void wrapAndThrow(Throwable t,
                                    Object bean,
                                    int index)
                  throws IOException
Deprecated. Since 1.7 use variant that takes DeserializationContext

Throws:
IOException