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
static class BeanDeserializer.CreatorContainer
          Container for set of Creators (constructors, factory methods)
 
Nested classes/interfaces inherited from class org.codehaus.jackson.map.deser.StdDeserializer
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
 
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  JavaType _beanType
           
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.BeanDeserializer.DelegatingCreator _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  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  org.codehaus.jackson.map.deser.BeanDeserializer.NumberCreator _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  org.codehaus.jackson.map.deser.BeanDeserializer.PropertyBasedCreator _propertyBasedCreator
          If the beans need to be instantiated using constructor or factory method that takes one or more named properties as argument(s), this creator is used for serialization.
protected  HashMap<String,SettableBeanProperty> _props
          Things set via setters (modifiers) are included in this Map.
protected  org.codehaus.jackson.map.deser.BeanDeserializer.StringCreator _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.
 
Constructor Summary
BeanDeserializer(JavaType type)
           
 
Method Summary
protected  Object _deserializeProperties(JsonParser jp, DeserializationContext ctxt, Object bean)
          Method that will process "extra" properties that follow Creator-bound properties (if any).
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.
 void addIgnorable(String propName)
          Method that will add property name as one of properties that can be ignored if not recognized.
 void addProperty(SettableBeanProperty prop)
          Method to add a property setter.
 Object deserialize(JsonParser jp, DeserializationContext ctxt)
          Method that can be called to ask implementation to deserialize json content into the value type this serializer handles.
 Object deserializeFromNumber(JsonParser jp, DeserializationContext ctxt)
           
 Object deserializeFromObject(JsonParser jp, DeserializationContext ctxt)
           
 Object deserializeFromString(JsonParser jp, DeserializationContext ctxt)
           
protected  JsonDeserializer<Object> findDeserializer(DeserializationConfig config, DeserializerProvider provider, JavaType type, String propertyName, HashMap<JavaType,JsonDeserializer<Object>> seen)
          Helper method used to locate deserializers for properties the bean itself contains.
 Class<?> getBeanClass()
           
protected  void handleUnknownProperty(DeserializationContext ctxt, Object beanOrClass, String propName)
          Method called to deal with a property that did not map to a known Bean property.
 SettableBeanProperty removeProperty(String name)
           
 void resolve(DeserializationConfig config, DeserializerProvider provider)
          Method called to finalize setup of this deserializer, after deserializer itself has been registered.
 void setAnySetter(SettableAnyProperty s)
           
 void setCreators(BeanDeserializer.CreatorContainer creators)
          Method called by factory after it has introspected all available Creators (constructors, static factory methods).
 void setDefaultConstructor(Constructor<?> ctor)
           
 void validateCreators()
          Method called to ensure that there is at least one constructor that could be used to construct an instance.
 
Methods inherited from class org.codehaus.jackson.map.deser.StdDeserializer
_parseBoolean, _parseDate, _parseDouble, _parseFloat, _parseInt, _parseLong, _parseShort, getValueClass, reportUnknownProperty
 
Methods inherited from class org.codehaus.jackson.map.JsonDeserializer
deserialize, getNullValue, shouldBeCached
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_beanType

protected final JavaType _beanType

_defaultConstructor

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


_stringCreator

protected org.codehaus.jackson.map.deser.BeanDeserializer.StringCreator _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 org.codehaus.jackson.map.deser.BeanDeserializer.NumberCreator _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 org.codehaus.jackson.map.deser.BeanDeserializer.DelegatingCreator _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 org.codehaus.jackson.map.deser.BeanDeserializer.PropertyBasedCreator _propertyBasedCreator
If the beans need to be instantiated using constructor or factory method that takes one or more named properties as argument(s), this creator is used for serialization.


_props

protected final HashMap<String,SettableBeanProperty> _props
Things set via setters (modifiers) are included in this Map.


_anySetter

protected 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 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.

Constructor Detail

BeanDeserializer

public BeanDeserializer(JavaType type)
Method Detail

setDefaultConstructor

public void setDefaultConstructor(Constructor<?> ctor)

setCreators

public void setCreators(BeanDeserializer.CreatorContainer creators)
Method called by factory after it has introspected all available Creators (constructors, static factory methods).


addProperty

public void addProperty(SettableBeanProperty prop)
Method to add a property setter. Will ensure that there is no unexpected override; if one is found will throw a IllegalArgumentException.


removeProperty

public SettableBeanProperty removeProperty(String name)

setAnySetter

public void setAnySetter(SettableAnyProperty s)

addIgnorable

public void addIgnorable(String propName)
Method that will add property name as one of properties that can be ignored if not recognized.


validateCreators

public void validateCreators()
                      throws JsonMappingException
Method called to ensure that there is at least one constructor that could be used to construct an instance.

Throws:
JsonMappingException

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
Description copied from class: JsonDeserializer
Method that can be called to ask implementation to deserialize json content into the value type this serializer handles. Returned instance is to be constructed by method itself.

Pre-condition for this method is that the parser points to the first event that is part of value to deserializer (and which is never Json 'null' literal, more on this below): for simple types it may be the only value; and for structured types the Object start marker. Post-condition is that the parser will point to the last event that is part of deserialized value (or in case deserialization fails, event that was not recognized or usable, which may be the same event as the one it pointed to upon call).

Note that this method is never called for JSON null literal, and thus deserializers need (and should) not check for it.

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

getBeanClass

public final Class<?> getBeanClass()

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

_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

_deserializeProperties

protected Object _deserializeProperties(JsonParser jp,
                                        DeserializationContext ctxt,
                                        Object bean)
                                 throws IOException,
                                        JsonProcessingException
Method that will process "extra" properties that follow Creator-bound properties (if any).

Throws:
IOException
JsonProcessingException

handleUnknownProperty

protected void handleUnknownProperty(DeserializationContext ctxt,
                                     Object beanOrClass,
                                     String propName)
                              throws IOException,
                                     JsonProcessingException
Description copied from class: StdDeserializer
Method called to deal with a property that did not map to a known Bean property. Method can deal with the problem as it sees fit (ignore, throw exception); but if it does return, it has to skip the matching Json content parser has.

Overrides:
handleUnknownProperty in class StdDeserializer<Object>
Parameters:
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

findDeserializer

protected JsonDeserializer<Object> findDeserializer(DeserializationConfig config,
                                                    DeserializerProvider provider,
                                                    JavaType type,
                                                    String propertyName,
                                                    HashMap<JavaType,JsonDeserializer<Object>> seen)
                                             throws JsonMappingException
Helper method used to locate deserializers for properties the bean itself contains.

Throws:
JsonMappingException