org.codehaus.jackson.map.introspect
Class BasicBeanDescription

java.lang.Object
  extended by org.codehaus.jackson.map.BeanDescription
      extended by org.codehaus.jackson.map.introspect.BasicBeanDescription

public class BasicBeanDescription
extends BeanDescription

Default BeanDescription implementation. Can theoretically be subclassed to customize some aspects of property introspection.


Field Summary
protected  AnnotationIntrospector _annotationIntrospector
           
protected  TypeBindings _bindings
          We may need type bindings for the bean type.
protected  AnnotatedClass _classInfo
          Information collected about the class introspected.
 
Fields inherited from class org.codehaus.jackson.map.BeanDescription
_type
 
Constructor Summary
BasicBeanDescription(JavaType type, AnnotatedClass ac, AnnotationIntrospector ai)
           
 
Method Summary
 LinkedHashMap<String,AnnotatedField> _findPropertyFields(VisibilityChecker<?> vchecker, Collection<String> ignoredProperties, boolean forSerialization)
           
 TypeBindings bindingsForBeanType()
           
static String descFor(AnnotatedElement elem)
          Helper method used to describe an annotated element of type Class or Method.
 AnnotatedMethod findAnyGetter()
          Method used to locate the method of introspected class that implements JsonAnyGetter.
 AnnotatedMethod findAnySetter()
          Method used to locate the method of introspected class that implements JsonAnySetter.
 Map<String,AnnotatedMember> findBackReferenceProperties()
          Method for locating all back-reference properties (setters, fields) bean has
 List<String> findCreatorPropertyNames()
          Method for getting ordered list of named Creator properties.
 Constructor<?> findDefaultConstructor()
          Method that will locate the no-arg constructor for this class, if it has one, and that constructor has not been marked as ignorable.
 LinkedHashMap<String,AnnotatedField> findDeserializableFields(VisibilityChecker<?> vchecker, Collection<String> ignoredProperties)
           
 Method findFactoryMethod(Class<?>... expArgTypes)
          Method that can be called to find if introspected class declares a static "valueOf" factory method that returns an instance of introspected type, given one of acceptable types.
 LinkedHashMap<String,AnnotatedMethod> findGetters(VisibilityChecker<?> visibilityChecker, Collection<String> ignoredProperties)
           
 AnnotatedMethod findJsonValueMethod()
          Method for locating the getter method that is annotated with JsonValue annotation, if any.
 AnnotatedMethod findMethod(String name, Class<?>[] paramTypes)
           
 LinkedHashMap<String,AnnotatedField> findSerializableFields(VisibilityChecker<?> vchecker, Collection<String> ignoredProperties)
           
 JsonSerialize.Inclusion findSerializationInclusion(JsonSerialize.Inclusion defValue)
          Method for determining whether null properties should be written out for a Bean of introspected type.
 LinkedHashMap<String,AnnotatedMethod> findSetters(VisibilityChecker<?> vchecker)
           
 Constructor<?> findSingleArgConstructor(Class<?>... argTypes)
          Method that can be called to locate a single-arg constructor that takes specified exact type (will not accept supertype constructors)
 AnnotatedClass getClassInfo()
           
 List<AnnotatedConstructor> getConstructors()
           
 List<AnnotatedMethod> getFactoryMethods()
           
 boolean hasKnownClassAnnotations()
          Method for checking whether class being described has any annotations recognized by registered annotation introspector.
 Object instantiateBean(boolean fixAccess)
           
protected  boolean isCglibGetCallbacks(AnnotatedMethod am)
          This method was added to address [JACKSON-53]: need to weed out CGLib-injected "getCallbacks".
protected  boolean isFactoryMethod(AnnotatedMethod am)
           
protected  boolean isGroovyMetaClassGetter(AnnotatedMethod am)
          Another helper method to deal with rest of [JACKSON-103]
protected  boolean isGroovyMetaClassSetter(AnnotatedMethod am)
          Similar to isCglibGetCallbacks(org.codehaus.jackson.map.introspect.AnnotatedMethod), need to suppress a cyclic reference to resolve [JACKSON-103]
protected  String mangleGetterName(Annotated a, String basename)
           
static String manglePropertyName(String basename)
          Method called to figure out name of the property, given corresponding suggested name based on a method or field name.
protected  String mangleSetterName(Annotated a, String basename)
           
 String okNameForAnyGetter(AnnotatedMethod am, String name)
           
 String okNameForGetter(AnnotatedMethod am, String name)
           
 String okNameForIsGetter(AnnotatedMethod am, String name)
           
 String okNameForSetter(AnnotatedMethod am)
           
 
Methods inherited from class org.codehaus.jackson.map.BeanDescription
getBeanClass, getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_classInfo

protected final AnnotatedClass _classInfo
Information collected about the class introspected.


_annotationIntrospector

protected final AnnotationIntrospector _annotationIntrospector

_bindings

protected TypeBindings _bindings
We may need type bindings for the bean type. If so, we'll construct it lazily

Constructor Detail

BasicBeanDescription

public BasicBeanDescription(JavaType type,
                            AnnotatedClass ac,
                            AnnotationIntrospector ai)
Method Detail

getClassInfo

public AnnotatedClass getClassInfo()

hasKnownClassAnnotations

public boolean hasKnownClassAnnotations()
Method for checking whether class being described has any annotations recognized by registered annotation introspector.


findMethod

public AnnotatedMethod findMethod(String name,
                                  Class<?>[] paramTypes)

instantiateBean

public Object instantiateBean(boolean fixAccess)
Parameters:
fixAccess - If true, method is allowed to fix access to the default constructor (to be able to call non-public constructor); if false, has to use constructor as is.
Returns:
Instance of class represented by this descriptor, if suitable default constructor was found; null otherwise.

bindingsForBeanType

public TypeBindings bindingsForBeanType()

findGetters

public LinkedHashMap<String,AnnotatedMethod> findGetters(VisibilityChecker<?> visibilityChecker,
                                                         Collection<String> ignoredProperties)
Specified by:
findGetters in class BeanDescription
Parameters:
visibilityChecker - Object that determines whether methods have enough visibility to be auto-detectable as getters
ignoredProperties - (optional, may be null) Names of properties to ignore; getters for these properties are not to be returned.
Returns:
Ordered Map with logical property name as key, and matching getter method as value.

findJsonValueMethod

public AnnotatedMethod findJsonValueMethod()
Method for locating the getter method that is annotated with JsonValue annotation, if any. If multiple ones are found, an error is reported by throwing IllegalArgumentException


findDefaultConstructor

public Constructor<?> findDefaultConstructor()
Method that will locate the no-arg constructor for this class, if it has one, and that constructor has not been marked as ignorable. Method will also ensure that the constructor is accessible.


getConstructors

public List<AnnotatedConstructor> getConstructors()

getFactoryMethods

public List<AnnotatedMethod> getFactoryMethods()

findSingleArgConstructor

public Constructor<?> findSingleArgConstructor(Class<?>... argTypes)
Method that can be called to locate a single-arg constructor that takes specified exact type (will not accept supertype constructors)

Parameters:
argTypes - Type(s) of the argument that we are looking for

findFactoryMethod

public Method findFactoryMethod(Class<?>... expArgTypes)
Method that can be called to find if introspected class declares a static "valueOf" factory method that returns an instance of introspected type, given one of acceptable types.

Parameters:
expArgTypes - Types that the matching single argument factory method can take: will also accept super types of these types (ie. arg just has to be assignable from expArgType)

isFactoryMethod

protected boolean isFactoryMethod(AnnotatedMethod am)

findCreatorPropertyNames

public List<String> findCreatorPropertyNames()
Method for getting ordered list of named Creator properties. Returns an empty list is none found. If multiple Creator methods are defined, order between properties from different methods is undefined; however, properties for each such Creator are ordered properly relative to each other. For the usual case of just a single Creator, named properties are thus properly ordered.


findSerializableFields

public LinkedHashMap<String,AnnotatedField> findSerializableFields(VisibilityChecker<?> vchecker,
                                                                   Collection<String> ignoredProperties)

findSerializationInclusion

public JsonSerialize.Inclusion findSerializationInclusion(JsonSerialize.Inclusion defValue)
Method for determining whether null properties should be written out for a Bean of introspected type. This is based on global feature (lowest priority, passed as argument) and per-class annotation (highest priority).


findSetters

public LinkedHashMap<String,AnnotatedMethod> findSetters(VisibilityChecker<?> vchecker)
Specified by:
findSetters in class BeanDescription
Parameters:
vchecker - (optional) Object that determines whether specific methods have enough visibility to be considered as auto-detectable setters. If null, auto-detection is disabled
Returns:
Ordered Map with logical property name as key, and matching setter method as value.

findAnySetter

public AnnotatedMethod findAnySetter()
                              throws IllegalArgumentException
Method used to locate the method of introspected class that implements JsonAnySetter. If no such method exists null is returned. If more than one are found, an exception is thrown. Additional checks are also made to see that method signature is acceptable: needs to take 2 arguments, first one String or Object; second any can be any type.

Throws:
IllegalArgumentException

findAnyGetter

public AnnotatedMethod findAnyGetter()
                              throws IllegalArgumentException
Method used to locate the method of introspected class that implements JsonAnyGetter. If no such method exists null is returned. If more than one are found, an exception is thrown.

Throws:
IllegalArgumentException
Since:
1.6

findBackReferenceProperties

public Map<String,AnnotatedMember> findBackReferenceProperties()
Method for locating all back-reference properties (setters, fields) bean has

Since:
1.6

findDeserializableFields

public LinkedHashMap<String,AnnotatedField> findDeserializableFields(VisibilityChecker<?> vchecker,
                                                                     Collection<String> ignoredProperties)

okNameForAnyGetter

public String okNameForAnyGetter(AnnotatedMethod am,
                                 String name)

okNameForGetter

public String okNameForGetter(AnnotatedMethod am,
                              String name)

okNameForIsGetter

public String okNameForIsGetter(AnnotatedMethod am,
                                String name)

mangleGetterName

protected String mangleGetterName(Annotated a,
                                  String basename)
Returns:
Null to indicate that method is not a valid accessor; otherwise name of the property it is accessor for

isCglibGetCallbacks

protected boolean isCglibGetCallbacks(AnnotatedMethod am)
This method was added to address [JACKSON-53]: need to weed out CGLib-injected "getCallbacks". At this point caller has detected a potential getter method with name "getCallbacks" and we need to determine if it is indeed injectect by Cglib. We do this by verifying that the result type is "net.sf.cglib.proxy.Callback[]"

Also, see [JACKSON-177]; Hibernate may repackage cglib it uses, so we better catch that too


isGroovyMetaClassSetter

protected boolean isGroovyMetaClassSetter(AnnotatedMethod am)
Similar to isCglibGetCallbacks(org.codehaus.jackson.map.introspect.AnnotatedMethod), need to suppress a cyclic reference to resolve [JACKSON-103]


isGroovyMetaClassGetter

protected boolean isGroovyMetaClassGetter(AnnotatedMethod am)
Another helper method to deal with rest of [JACKSON-103]


okNameForSetter

public String okNameForSetter(AnnotatedMethod am)

mangleSetterName

protected String mangleSetterName(Annotated a,
                                  String basename)
Returns:
Null to indicate that method is not a valid accessor; otherwise name of the property it is accessor for

_findPropertyFields

public LinkedHashMap<String,AnnotatedField> _findPropertyFields(VisibilityChecker<?> vchecker,
                                                                Collection<String> ignoredProperties,
                                                                boolean forSerialization)
Parameters:
vchecker - (optional) Object that determines whether specific fields have enough visibility to be considered for inclusion; if null, auto-detection is disabled
ignoredProperties - (optional) names of properties to ignore; any fields that would be recognized as one of these properties is ignored.
forSerialization - If true, will collect serializable property fields; if false, deserializable
Returns:
Ordered Map with logical property name as key, and matching field as value.

manglePropertyName

public static String manglePropertyName(String basename)
Method called to figure out name of the property, given corresponding suggested name based on a method or field name.

Parameters:
basename - Name of accessor/mutator method, not including prefix ("get"/"is"/"set")

descFor

public static String descFor(AnnotatedElement elem)
Helper method used to describe an annotated element of type Class or Method.