org.codehaus.jackson.map.deser
Class BeanDeserializer

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

public class BeanDeserializer
extends JsonDeserializer<java.lang.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.


Field Summary
protected  SettableAnyProperty _anySetter
          Fallback setter used for handling any properties that are not mapped to regular setters.
protected  JavaType _beanType
           
protected  java.lang.reflect.Constructor<?> _defaultConstructor
          Default constructor used to instantiate the bean when mapping from Json object.
protected  java.util.HashSet<java.lang.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.NumberConstructor _numberConstructor
          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  java.util.HashMap<java.lang.String,SettableBeanProperty> _props
          Things set via setters (modifiers) are included in this Map.
protected  org.codehaus.jackson.map.deser.BeanDeserializer.StringConstructor _stringConstructor
          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 static void _rethrow(java.lang.Exception e)
           
 void addIgnorable(java.lang.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.
 java.lang.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.
 java.lang.Object deserializeFromObject(JsonParser jp, DeserializationContext ctxt)
           
 java.lang.Class<?> getBeanClass()
           
protected  void handleUnknownProperty(DeserializationContext ctxt, java.lang.Object resultBean, java.lang.String propName)
          Method called to deal with a property that did not map to a known Bean property.
 SettableBeanProperty removeProperty(java.lang.String name)
           
protected  void reportUnknownField(DeserializationContext ctxt, java.lang.Object resultBean, java.lang.String fieldName)
           
 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 setConstructor(org.codehaus.jackson.map.deser.BeanDeserializer.NumberConstructor ctor)
           
 void setConstructor(org.codehaus.jackson.map.deser.BeanDeserializer.StringConstructor ctor)
           
 void setDefaultConstructor(java.lang.reflect.Constructor<?> ctor)
           
 boolean shouldBeCached()
          Because of costs associated with constructing bean deserializers, they usually should be cached unlike other deserializer types.
 void validateConstructors()
          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.JsonDeserializer
deserialize, getNullValue
 
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 java.lang.reflect.Constructor<?> _defaultConstructor
Default constructor used to instantiate the bean when mapping from Json object.


_stringConstructor

protected org.codehaus.jackson.map.deser.BeanDeserializer.StringConstructor _stringConstructor
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.


_numberConstructor

protected org.codehaus.jackson.map.deser.BeanDeserializer.NumberConstructor _numberConstructor
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.


_props

protected final java.util.HashMap<java.lang.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 java.util.HashSet<java.lang.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(java.lang.reflect.Constructor<?> ctor)

setConstructor

public void setConstructor(org.codehaus.jackson.map.deser.BeanDeserializer.StringConstructor ctor)

setConstructor

public void setConstructor(org.codehaus.jackson.map.deser.BeanDeserializer.NumberConstructor ctor)

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(java.lang.String name)

setAnySetter

public void setAnySetter(SettableAnyProperty s)

addIgnorable

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


validateConstructors

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


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

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

shouldBeCached

public boolean shouldBeCached()
Because of costs associated with constructing bean deserializers, they usually should be cached unlike other deserializer types. Additionally it is important to be able to cache bean serializers to handle cyclic references.

Overrides:
shouldBeCached in class JsonDeserializer<java.lang.Object>

deserialize

public final java.lang.Object deserialize(JsonParser jp,
                                          DeserializationContext ctxt)
                                   throws java.io.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<java.lang.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:
java.io.IOException
JsonProcessingException

getBeanClass

public final java.lang.Class<?> getBeanClass()

deserializeFromObject

public java.lang.Object deserializeFromObject(JsonParser jp,
                                              DeserializationContext ctxt)
                                       throws java.io.IOException,
                                              JsonProcessingException
Throws:
java.io.IOException
JsonProcessingException

handleUnknownProperty

protected void handleUnknownProperty(DeserializationContext ctxt,
                                     java.lang.Object resultBean,
                                     java.lang.String propName)
                              throws java.io.IOException,
                                     JsonProcessingException
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.

Parameters:
ctxt - Context for deserialization; allows access to the parser, error reporting functionality
resultBean - Bean that is being populated by this deserializer
propName - Name of the property that can not be mapped
Throws:
java.io.IOException
JsonProcessingException

reportUnknownField

protected void reportUnknownField(DeserializationContext ctxt,
                                  java.lang.Object resultBean,
                                  java.lang.String fieldName)
                           throws java.io.IOException,
                                  JsonProcessingException
Throws:
java.io.IOException
JsonProcessingException

_rethrow

protected static void _rethrow(java.lang.Exception e)
                        throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException