Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser;
  
  import java.util.*;
  
  
Concrete deserializer factory class that adds full Bean deserializer construction logic using class introspection. Note that factories specifically do not implement any form of caching: aside from configuration they are stateless; caching is implemented by other components.

Instances of this class are fully immutable as all configuration is done by using "fluent factories" (methods that construct new factory instances with different configuration, instead of modifying instance).

 
 public class BeanDeserializerFactory
     extends BasicDeserializerFactory
     implements java.io.Serializable // since 2.1
 {
     private static final long serialVersionUID = 1;

    
Signature of Throwable.initCause method.
 
     private final static Class<?>[] INIT_CAUSE_PARAMS = new Class<?>[] { Throwable.class };
 
     private final static Class<?>[] NO_VIEWS = new Class<?>[0];
     
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
    
    
Globally shareable thread-safe instance which has no additional custom deserializers registered
 
     public final static BeanDeserializerFactory instance = new BeanDeserializerFactory(
             new DeserializerFactoryConfig());
 
         super(config);
     }
    
    
Method used by module registration functionality, to construct a new bean deserializer factory with different configuration settings.
 
     @Override
     {
         if ( == config) {
             return this;
         }
         /* 22-Nov-2010, tatu: Handling of subtypes is tricky if we do immutable-with-copy-ctor;
          *    and we pretty much have to here either choose between losing subtype instance
          *    when registering additional deserializers, or losing deserializers.
          *    Instead, let's actually just throw an error if this method is called when subtype
          *    has not properly overridden this method; this to indicate problem as soon as possible.
          */
         if (getClass() != BeanDeserializerFactory.class) {
             throw new IllegalStateException("Subtype of BeanDeserializerFactory ("+getClass().getName()
                     +") has not properly overridden method 'withAdditionalDeserializers': can not instantiate subtype with "
                     +"additional deserializer definitions");
         }
         return new BeanDeserializerFactory(config);
     }
     
     /*
     /**********************************************************
     /* Overrides for super-class methods used for finding
     /* custom deserializers
     /**********************************************************
      */
 
     // Note: NOT overriding, superclass has no matching method
     @SuppressWarnings("unchecked")
            DeserializationConfig configBeanDescription beanDesc)
        throws JsonMappingException
    {
        for (Deserializers d  : .deserializers()) {
            JsonDeserializer<?> deser = d.findBeanDeserializer(typeconfigbeanDesc);
            if (deser != null) {
                return (JsonDeserializer<Object>) deser;
            }
        }
        return null;
    }
    
    /*
    /**********************************************************
    /* DeserializerFactory API implementation
    /**********************************************************
     */

    
Method that DeserializerCaches call to create a new deserializer for types other than Collections, Maps, arrays and enums.
    @Override
            JavaType typeBeanDescription beanDesc)
        throws JsonMappingException
    {
        final DeserializationConfig config = ctxt.getConfig();
        // We may also have custom overrides:
        JsonDeserializer<Objectcustom = _findCustomBeanDeserializer(typeconfigbeanDesc);
        if (custom != null) {
            return custom;
        }
        /* One more thing to check: do we have an exception type
         * (Throwable or its sub-classes)? If so, need slightly
         * different handling.
         */
        if (type.isThrowable()) {
            return buildThrowableDeserializer(ctxttypebeanDesc);
        }
        /* Or, for abstract types, may have alternate means for resolution
         * (defaulting, materialization)
         */
        if (type.isAbstract()) {
            // [JACKSON-41] (v1.6): Let's make it possible to materialize abstract types.
            JavaType concreteType = materializeAbstractType(ctxttypebeanDesc);
            if (concreteType != null) {
                /* important: introspect actual implementation (abstract class or
                 * interface doesn't have constructors, for one)
                 */
                beanDesc = config.introspect(concreteType);
                return buildBeanDeserializer(ctxtconcreteTypebeanDesc);
            }
        }
        // Otherwise, may want to check handlers for standard types, from superclass:
        @SuppressWarnings("unchecked")
        JsonDeserializer<Objectdeser = (JsonDeserializer<Object>) findStdDeserializer(ctxttypebeanDesc);
        if (deser != null) {
            return deser;
        }
        // Otherwise: could the class be a Bean class? If not, bail out
        if (!isPotentialBeanType(type.getRawClass())) {
            return null;
        }
        // Use generic bean introspection to build deserializer
        return buildBeanDeserializer(ctxttypebeanDesc);
    }
    @Override
    		DeserializationContext ctxtJavaType valueTypeBeanDescription beanDesc,
    		Class<?> builderClass)
        throws JsonMappingException
    {
    	// First: need a BeanDescription for builder class
    	JavaType builderType = ctxt.constructType(builderClass);
    	BeanDescription builderDesc = ctxt.getConfig().introspectForBuilder(builderType);
    	return buildBuilderBasedDeserializer(ctxtvalueTypebuilderDesc);
    }
    
    
Method called by BeanDeserializerFactory to see if there might be a standard deserializer registered for given type.
            JavaType typeBeanDescription beanDesc)
        throws JsonMappingException
    {
        // note: we do NOT check for custom deserializers here, caller has already
        // done that
        JsonDeserializer<?> deser = findDefaultDeserializer(ctxttypebeanDesc);
        if (deser != null) {
            return deser;
        }
        
        Class<?> cls = type.getRawClass();
        // [JACKSON-283]: AtomicReference is a rather special type...
        if (AtomicReference.class.isAssignableFrom(cls)) {
            // Must find parameterization
            TypeFactory tf = ctxt.getTypeFactory();
            JavaType[] params = tf.findTypeParameters(typeAtomicReference.class);
            JavaType referencedType;
            if (params == null || params.length < 1) { // untyped (raw)
                referencedType = TypeFactory.unknownType();
            } else {
                referencedType = params[0];
            }
            TypeDeserializer valueTypeDeser = findTypeDeserializer(ctxt.getConfig(), referencedType);
            BeanDescription refdDesc = ctxt.getConfig().introspectClassAnnotations(referencedType);
            deser = findDeserializerFromAnnotation(ctxtrefdDesc.getClassInfo());
            return new AtomicReferenceDeserializer(referencedTypevalueTypeDeserdeser);
        }
        return findOptionalStdDeserializer(ctxttypebeanDesc);
    }

    
Overridable method called after checking all other types.

Since:
2.2
            JavaType typeBeanDescription beanDesc)
        throws JsonMappingException
    {
        return ..findDeserializer(typectxt.getConfig(), beanDesc);
    }
    
            JavaType typeBeanDescription beanDesc)
        throws JsonMappingException
    {
        final JavaType abstractType = beanDesc.getType();
        // [JACKSON-502]: Now it is possible to have multiple resolvers too,
        //   as they are registered via module interface.
            JavaType concrete = r.resolveAbstractType(ctxt.getConfig(), abstractType);
            if (concrete != null) {
                return concrete;
            }
        }
        return null;
    }
    
    /*
    /**********************************************************
    /* Public construction method beyond DeserializerFactory API:
    /* can be called from outside as well as overridden by
    /* sub-classes
    /**********************************************************
     */

    
Method that is to actually build a bean deserializer instance. All basic sanity checks have been done to know that what we have may be a valid bean type, and that there are no default simple deserializers.
    @SuppressWarnings("unchecked")
            JavaType typeBeanDescription beanDesc)
        throws JsonMappingException
    {
        // First: check what creators we can use, if any
        ValueInstantiator valueInstantiator = findValueInstantiator(ctxtbeanDesc);
        BeanDeserializerBuilder builder = constructBeanDeserializerBuilder(ctxtbeanDesc);
        builder.setValueInstantiator(valueInstantiator);
         // And then setters for deserializing from JSON Object
        addBeanProps(ctxtbeanDescbuilder);
        addObjectIdReader(ctxtbeanDescbuilder);
        // managed/back reference fields/setters need special handling... first part
        addReferenceProperties(ctxtbeanDescbuilder);
        addInjectables(ctxtbeanDescbuilder);
        
        final DeserializationConfig config = ctxt.getConfig();
        // [JACKSON-440]: update builder now that all information is in?
        if (.hasDeserializerModifiers()) {
            for (BeanDeserializerModifier mod : .deserializerModifiers()) {
                builder = mod.updateBuilder(configbeanDescbuilder);
            }
        }
        JsonDeserializer<?> deserializer;
        /* 19-Mar-2012, tatu: This check used to be done earlier; but we have to defer
         *   it a bit to collect information on ObjectIdReader, for example.
         */
        if (type.isAbstract() && !valueInstantiator.canInstantiate()) {
            deserializer = builder.buildAbstract();
        } else {
            deserializer = builder.build();
        }
        // [JACKSON-440]: may have modifier(s) that wants to modify or replace serializer we just built:
        if (.hasDeserializerModifiers()) {
            for (BeanDeserializerModifier mod : .deserializerModifiers()) {
                deserializer = mod.modifyDeserializer(configbeanDescdeserializer);
            }
        }
        return (JsonDeserializer<Object>) deserializer;
    }
    
    
Method for constructing a bean deserializer that uses specified intermediate Builder for binding data, and construction of the value instance. Note that implementation is mostly copied from the regular BeanDeserializer build method.
    @SuppressWarnings("unchecked")
    		DeserializationContext ctxtJavaType valueTypeBeanDescription builderDesc)
        throws JsonMappingException
    {
    	// Creators, anyone? (to create builder itself)
        ValueInstantiator valueInstantiator = findValueInstantiator(ctxtbuilderDesc);
        final DeserializationConfig config = ctxt.getConfig();
        BeanDeserializerBuilder builder = constructBeanDeserializerBuilder(ctxtbuilderDesc);
        builder.setValueInstantiator(valueInstantiator);
         // And then "with methods" for deserializing from JSON Object
        addBeanProps(ctxtbuilderDescbuilder);
        addObjectIdReader(ctxtbuilderDescbuilder);
        
        // managed/back reference fields/setters need special handling... first part
        addReferenceProperties(ctxtbuilderDescbuilder);
        addInjectables(ctxtbuilderDescbuilder);
        JsonPOJOBuilder.Value builderConfig = builderDesc.findPOJOBuilderConfig();
        final String buildMethodName = (builderConfig == null) ?
                "build" : builderConfig.buildMethodName;
        
        // and lastly, find build method to use:
        AnnotatedMethod buildMethod = builderDesc.findMethod(buildMethodNamenull);
        if (buildMethod != null) { // note: can't yet throw error; may be given build method
            if (config.canOverrideAccessModifiers()) {
            	ClassUtil.checkAndFixAccess(buildMethod.getMember());
            }
        }
        builder.setPOJOBuilder(buildMethodbuilderConfig);
        // this may give us more information...
        if (.hasDeserializerModifiers()) {
            for (BeanDeserializerModifier mod : .deserializerModifiers()) {
                builder = mod.updateBuilder(configbuilderDescbuilder);
            }
        }
        JsonDeserializer<?> deserializer = builder.buildBuilderBased(
        		valueTypebuildMethodName);
        // [JACKSON-440]: may have modifier(s) that wants to modify or replace serializer we just built:
        if (.hasDeserializerModifiers()) {
            for (BeanDeserializerModifier mod : .deserializerModifiers()) {
                deserializer = mod.modifyDeserializer(configbuilderDescdeserializer);
            }
        }
        return (JsonDeserializer<Object>) deserializer;
    }
    
    protected void addObjectIdReader(DeserializationContext ctxt,
            BeanDescription beanDescBeanDeserializerBuilder builder)
        throws JsonMappingException
    {
        ObjectIdInfo objectIdInfo = beanDesc.getObjectIdInfo();
        if (objectIdInfo == null) {
            return;
        }
        Class<?> implClass = objectIdInfo.getGeneratorType();
        JavaType idType;
    	SettableBeanProperty idProp;
        ObjectIdGenerator<?> gen;
        // Just one special case: Property-based generator is trickier
        if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work
            PropertyName propName = objectIdInfo.getPropertyName();
            idProp = builder.findProperty(propName);
            if (idProp == null) {
                throw new IllegalArgumentException("Invalid Object Id definition for "
                        +beanDesc.getBeanClass().getName()+": can not find property with name '"+propName+"'");
            }
            idType = idProp.getType();
            gen = new PropertyBasedObjectIdGenerator(objectIdInfo.getScope());
        } else {
            JavaType type = ctxt.constructType(implClass);
            idType = ctxt.getTypeFactory().findTypeParameters(typeObjectIdGenerator.class)[0];
            idProp = null;
            gen = ctxt.objectIdGeneratorInstance(beanDesc.getClassInfo(), objectIdInfo);
        }
        // also: unlike with value deserializers, let's just resolve one we need here
        JsonDeserializer<?> deser = ctxt.findRootValueDeserializer(idType);
        builder.setObjectIdReader(ObjectIdReader.construct(idType,
                objectIdInfo.getPropertyName(), gendeseridProp));
    }
    
    @SuppressWarnings("unchecked")
            JavaType typeBeanDescription beanDesc)
        throws JsonMappingException
    {
        final DeserializationConfig config = ctxt.getConfig();
        // first: construct like a regular bean deserializer...
        BeanDeserializerBuilder builder = constructBeanDeserializerBuilder(ctxtbeanDesc);
        builder.setValueInstantiator(findValueInstantiator(ctxtbeanDesc));
        addBeanProps(ctxtbeanDescbuilder);
        // (and assume there won't be any back references)
        // But then let's decorate things a bit
        /* To resolve [JACKSON-95], need to add "initCause" as setter
         * for exceptions (sub-classes of Throwable).
         */
        AnnotatedMethod am = beanDesc.findMethod("initCause");
        if (am != null) { // should never be null
            SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(ctxt.getConfig(), am"cause");
            SettableBeanProperty prop = constructSettableProperty(ctxtbeanDescpropDef,
                    am.getGenericParameterType(0));
            if (prop != null) {
                /* 21-Aug-2011, tatus: We may actually have found 'cause' property
                 *   to set (with new 1.9 code)... but let's replace it just in case,
                 *   otherwise can end up with odd errors.
                 */
                builder.addOrReplaceProperty(proptrue);
            }
        }
        // And also need to ignore "localizedMessage"
        builder.addIgnorable("localizedMessage");
        // [JACKSON-794]: JDK 7 also added "getSuppressed", skip if we have such data:
        builder.addIgnorable("suppressed");
        /* As well as "message": it will be passed via constructor,
         * as there's no 'setMessage()' method
        */
        builder.addIgnorable("message");
        // [JACKSON-440]: update builder now that all information is in?
        if (.hasDeserializerModifiers()) {
            for (BeanDeserializerModifier mod : .deserializerModifiers()) {
                builder = mod.updateBuilder(configbeanDescbuilder);
            }
        }
        JsonDeserializer<?> deserializer = builder.build();
        
        /* At this point it ought to be a BeanDeserializer; if not, must assume
         * it's some other thing that can handle deserialization ok...
         */
        if (deserializer instanceof BeanDeserializer) {
            deserializer = new ThrowableDeserializer((BeanDeserializerdeserializer);
        }
        // [JACKSON-440]: may have modifier(s) that wants to modify or replace serializer we just built:
        if (.hasDeserializerModifiers()) {
            for (BeanDeserializerModifier mod : .deserializerModifiers()) {
                deserializer = mod.modifyDeserializer(configbeanDescdeserializer);
            }
        }
        return (JsonDeserializer<Object>) deserializer;
    }
    /*
    /**********************************************************
    /* Helper methods for Bean deserializer construction,
    /* overridable by sub-classes
    /**********************************************************
     */

    
Overridable method that constructs a BeanDeserializerBuilder which is used to accumulate information needed to create deserializer instance.
            BeanDescription beanDesc) {
        return new BeanDeserializerBuilder(beanDescctxt.getConfig());
    }
    
    
Method called to figure out settable properties for the bean deserializer to use.

Note: designed to be overridable, and effort is made to keep interface similar between versions.

    protected void addBeanProps(DeserializationContext ctxt,
            BeanDescription beanDescBeanDeserializerBuilder builder)
        throws JsonMappingException
    {
        final SettableBeanProperty[] creatorProps =
                builder.getValueInstantiator().getFromObjectArguments(ctxt.getConfig());
        
        // Things specified as "ok to ignore"? [JACKSON-77]
        AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
        boolean ignoreAny = false;
        {
            Boolean B = intr.findIgnoreUnknownProperties(beanDesc.getClassInfo());
            if (B != null) {
                ignoreAny = B.booleanValue();
                builder.setIgnoreUnknownProperties(ignoreAny);
            }
        }
        // Or explicit/implicit definitions?
        Set<Stringignored = ArrayBuilders.arrayToSet(intr.findPropertiesToIgnore(beanDesc.getClassInfo()));        
        for (String propName : ignored) {
            builder.addIgnorable(propName);
        }
        // Also, do we have a fallback "any" setter?
        AnnotatedMethod anySetter = beanDesc.findAnySetter();
        if (anySetter != null) {
            builder.setAnySetter(constructAnySetter(ctxtbeanDescanySetter));
        }
        // NOTE: we do NOT add @JsonIgnore'd properties into blocked ones if there's any setter
        // Implicit ones via @JsonIgnore and equivalent?
        if (anySetter == null) {
            Collection<Stringignored2 = beanDesc.getIgnoredPropertyNames();
            if (ignored2 != null) {
                for (String propName : ignored2) {
                    // allow ignoral of similarly named JSON property, but do not force;
                    // latter means NOT adding this to 'ignored':
                    builder.addIgnorable(propName);
                }
            }
        }
        final boolean useGettersAsSetters = (ctxt.isEnabled(.)
                && ctxt.isEnabled(.));
        // Ok: let's then filter out property definitions
        List<BeanPropertyDefinitionpropDefs = filterBeanProps(ctxt,
                beanDescbuilderbeanDesc.findProperties(), ignored);
        // After which we can let custom code change the set
        if (.hasDeserializerModifiers()) {
            for (BeanDeserializerModifier mod : .deserializerModifiers()) {
                propDefs = mod.updateProperties(ctxt.getConfig(), beanDescpropDefs);
            }
        }
        
        // At which point we still have all kinds of properties; not all with mutators:
        for (BeanPropertyDefinition propDef : propDefs) {
            SettableBeanProperty prop = null;
            /* 18-Oct-2013, tatu: Although constructor parameters have highest precedence,
             *   we need to do linkage (as per [Issue#318]), and so need to start with
             *   other types, and only then create constructor parameter, if any.
             */
            if (propDef.hasSetter()) {
                Type propertyType = propDef.getSetter().getGenericParameterType(0);
                prop = constructSettableProperty(ctxtbeanDescpropDefpropertyType);
            } else if (propDef.hasField()) {
                Type propertyType = propDef.getField().getGenericType();
                prop = constructSettableProperty(ctxtbeanDescpropDefpropertyType);
            } else if (useGettersAsSetters && propDef.hasGetter()) {
                /* As per [JACKSON-88], may also need to consider getters
                 * for Map/Collection properties; but with lowest precedence
                 */
                AnnotatedMethod getter = propDef.getGetter();
                // should only consider Collections and Maps, for now?
                Class<?> rawPropertyType = getter.getRawType();
                if (Collection.class.isAssignableFrom(rawPropertyType)
                        || Map.class.isAssignableFrom(rawPropertyType)) {
                    prop = constructSetterlessProperty(ctxtbeanDescpropDef);
                }
            }
            if (propDef.hasConstructorParameter()) {
                /* [JACKSON-700] If property is passed via constructor parameter, we must
                 *   handle things in special way. Not sure what is the most optimal way...
                 *   for now, let's just call a (new) method in builder, which does nothing.
                 */
                // but let's call a method just to allow custom builders to be aware...
                final String name = propDef.getName();
                CreatorProperty cprop = null;
                if (creatorProps != null) {
                    for (SettableBeanProperty cp : creatorProps) {
                        if (name.equals(cp.getName())) {
                            cprop = (CreatorPropertycp;
                            break;
                        }
                    }
                }
                if (cprop == null) {
                    throw ctxt.mappingException("Could not find creator property with name '"
                              +name+"' (in class "+beanDesc.getBeanClass().getName()+")");
                }
                if (prop != null) {
                    cprop = cprop.withFallbackSetter(prop);
                }
                prop = cprop;
                builder.addCreatorProperty(cprop);
                continue;
            }
            
            if (prop != null) {
                Class<?>[] views = propDef.findViews();
                if (views == null) {
                    // one more twist: if default inclusion disabled, need to force empty set of views
                    if (!ctxt.isEnabled(.)) {
                        views = ;
                    }
                }
                // one more thing before adding to builder: copy any metadata
                prop.setViews(views);
                builder.addProperty(prop);
            }
        }
    }
    
    
Helper method called to filter out explicit ignored properties, as well as properties that have "ignorable types". Note that this will not remove properties that have no setters.
            BeanDescription beanDescBeanDeserializerBuilder builder,
            List<BeanPropertyDefinitionpropDefsIn,
            Set<Stringignored)
        throws JsonMappingException
    {
                Math.max(4, propDefsIn.size()));
        HashMap<Class<?>,BooleanignoredTypes = new HashMap<Class<?>,Boolean>();
        // These are all valid setters, but we do need to introspect bit more
        for (BeanPropertyDefinition property : propDefsIn) {
            String name = property.getName();
            if (ignored.contains(name)) { // explicit ignoral using @JsonIgnoreProperties needs to block entries
                continue;
            }
            if (!property.hasConstructorParameter()) { // never skip constructor params
                Class<?> rawPropertyType = null;
                if (property.hasSetter()) {
                    rawPropertyType = property.getSetter().getRawParameterType(0);
                } else if (property.hasField()) {
                    rawPropertyType = property.getField().getRawType();
                }
                // [JACKSON-429] Some types are declared as ignorable as well
                if ((rawPropertyType != null)
                        && (isIgnorableType(ctxt.getConfig(), beanDescrawPropertyTypeignoredTypes))) {
                    // important: make ignorable, to avoid errors if value is actually seen
                    builder.addIgnorable(name);
                    continue;
                }
            }
            result.add(property);
        }
        return result;
    }
    
    
Method that will find if bean has any managed- or back-reference properties, and if so add them to bean, to be linked during resolution phase.
    protected void addReferenceProperties(DeserializationContext ctxt,
            BeanDescription beanDescBeanDeserializerBuilder builder)
        throws JsonMappingException
    {
        // and then back references, not necessarily found as regular properties
        Map<String,AnnotatedMemberrefs = beanDesc.findBackReferenceProperties();
        if (refs != null) {
            for (Map.Entry<StringAnnotatedMemberen : refs.entrySet()) {
                String name = en.getKey();
                AnnotatedMember m = en.getValue();
                Type genericType;
                if (m instanceof AnnotatedMethod) {
                    genericType = ((AnnotatedMethodm).getGenericParameterType(0);
                } else {
                    genericType = m.getRawType();
                }
                SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(
                		ctxt.getConfig(), m);
                builder.addBackReferenceProperty(nameconstructSettableProperty(
                        ctxtbeanDescpropDefgenericType));
            }
        }
    }
    
    
Method called locate all members used for value injection (if any), constructor com.fasterxml.jackson.databind.deser.impl.ValueInjector instances, and add them to builder.
    protected void addInjectables(DeserializationContext ctxt,
            BeanDescription beanDescBeanDeserializerBuilder builder)
        throws JsonMappingException
    {
        Map<ObjectAnnotatedMemberraw = beanDesc.findInjectables();
        if (raw != null) {
            boolean fixAccess = ctxt.canOverrideAccessModifiers();
            for (Map.Entry<ObjectAnnotatedMemberentry : raw.entrySet()) {
                AnnotatedMember m = entry.getValue();
                if (fixAccess) {
                    m.fixAccess(); // to ensure we can call it
                }
                builder.addInjectable(new PropertyName(m.getName()),
                        beanDesc.resolveType(m.getGenericType()),
                        beanDesc.getClassAnnotations(), mentry.getKey());
            }
        }
    }

    
Method called to construct fallback SettableAnyProperty for handling unknown bean properties, given a method that has been designated as such setter.
            BeanDescription beanDescAnnotatedMethod setter)
        throws JsonMappingException
    {
        if (ctxt.canOverrideAccessModifiers()) {
            setter.fixAccess(); // to ensure we can call it
        }
        // we know it's a 2-arg method, second arg is the value
        JavaType type = beanDesc.bindingsForBeanType().resolveType(setter.getGenericParameterType(1));
        BeanProperty.Std property = new BeanProperty.Std(new PropertyName(setter.getName()),
                typenullbeanDesc.getClassAnnotations(), setter,
                .);
        type = resolveType(ctxtbeanDesctypesetter);
        /* AnySetter can be annotated with @JsonClass (etc) just like a
         * regular setter... so let's see if those are used.
         * Returns null if no annotations, in which case binding will
         * be done at a later point.
         */
        JsonDeserializer<Objectdeser = findDeserializerFromAnnotation(ctxtsetter);
        /* Otherwise, method may specify more specific (sub-)class for
         * value (no need to check if explicit deser was specified):
         */
        type = modifyTypeByAnnotation(ctxtsettertype);
        if (deser == null) {
            deser = type.getValueHandler();
        }
        TypeDeserializer typeDeser = type.getTypeHandler();
        return new SettableAnyProperty(propertysettertype,
                desertypeDeser);
    }

    
Method that will construct a regular bean property setter using the given setter method.

Returns:
Property constructed, if any; or null to indicate that there should be no property based on given definitions.
            BeanDescription beanDescBeanPropertyDefinition propDef,
            Type jdkType)
        throws JsonMappingException
    {
        // need to ensure method is callable (for non-public)
        AnnotatedMember mutator = propDef.getNonConstructorMutator();
        if (ctxt.canOverrideAccessModifiers()) {
            mutator.fixAccess();
        }
        // note: this works since we know there's exactly one argument for methods
        JavaType t0 = beanDesc.resolveType(jdkType);
        BeanProperty.Std property = new BeanProperty.Std(propDef.getFullName(),
                t0propDef.getWrapperName(),
                beanDesc.getClassAnnotations(), mutatorpropDef.getMetadata());
        JavaType type = resolveType(ctxtbeanDesct0mutator);
        // did type change?
        if (type != t0) {
            property = property.withType(type);
        }
        
        /* First: does the Method specify the deserializer to use?
         * If so, let's use it.
         */
        JsonDeserializer<ObjectpropDeser = findDeserializerFromAnnotation(ctxtmutator);
        type = modifyTypeByAnnotation(ctxtmutatortype);
        TypeDeserializer typeDeser = type.getTypeHandler();
        SettableBeanProperty prop;
        if (mutator instanceof AnnotatedMethod) {
            prop = new MethodProperty(propDeftypetypeDeser,
                beanDesc.getClassAnnotations(), (AnnotatedMethodmutator);
        } else {
            prop = new FieldProperty(propDeftypetypeDeser,
                    beanDesc.getClassAnnotations(), (AnnotatedFieldmutator);
        }
        if (propDeser != null) {
            prop = prop.withValueDeserializer(propDeser);
        }
        // [JACKSON-235]: need to retain name of managed forward references:
        if (ref != null && ref.isManagedReference()) {
            prop.setManagedReferenceName(ref.getName());
        }
        return prop;
    }

    
Method that will construct a regular bean property setter using the given setter method.
            BeanDescription beanDescBeanPropertyDefinition propDef)
        throws JsonMappingException
    {
        final AnnotatedMethod getter = propDef.getGetter();
        // need to ensure it is callable now:
        if (ctxt.canOverrideAccessModifiers()) {
            getter.fixAccess();
        }
        /* 26-Jan-2012, tatu: Alas, this complication is still needed to handle
         *   (or at least work around) local type declarations...
         */
        JavaType type = getter.getType(beanDesc.bindingsForBeanType());
        /* First: does the Method specify the deserializer to use?
         * If so, let's use it.
         */
        JsonDeserializer<ObjectpropDeser = findDeserializerFromAnnotation(ctxtgetter);
        type = modifyTypeByAnnotation(ctxtgettertype);
        TypeDeserializer typeDeser = type.getTypeHandler();
        SettableBeanProperty prop = new SetterlessProperty(propDeftypetypeDeser,
                beanDesc.getClassAnnotations(), getter);
        if (propDeser != null) {
            prop = prop.withValueDeserializer(propDeser);
        }
        return prop;
    }
    /*
    /**********************************************************
    /* Helper methods for Bean deserializer, other
    /**********************************************************
     */

    
Helper method used to skip processing for types that we know can not be (i.e. are never consider to be) beans: things like primitives, Arrays, Enums, and proxy types.

Note that usually we shouldn't really be getting these sort of types anyway; but better safe than sorry.

    protected boolean isPotentialBeanType(Class<?> type)
    {
        String typeStr = ClassUtil.canBeABeanType(type);
        if (typeStr != null) {
            throw new IllegalArgumentException("Can not deserialize Class "+type.getName()+" (of type "+typeStr+") as a Bean");
        }
        if (ClassUtil.isProxyType(type)) {
            throw new IllegalArgumentException("Can not deserialize Proxy class "+type.getName()+" as a Bean");
        }
        /* also: can't deserialize some local classes: static are ok; in-method not;
         * and with [JACKSON-594], other non-static inner classes are ok
         */
        typeStr = ClassUtil.isLocalType(typetrue);
        if (typeStr != null) {
            throw new IllegalArgumentException("Can not deserialize Class "+type.getName()+" (of type "+typeStr+") as a Bean");
        }
    	return true;
    }

    
Helper method that will check whether given raw type is marked as always ignorable (for purpose of ignoring properties with type)
    protected boolean isIgnorableType(DeserializationConfig configBeanDescription beanDesc,
            Class<?> typeMap<Class<?>,BooleanignoredTypes)
    {
        Boolean status = ignoredTypes.get(type);
        if (status == null) {
            BeanDescription desc = config.introspectClassAnnotations(type);
            status = config.getAnnotationIntrospector().isIgnorableType(desc.getClassInfo());
            // We default to 'false', ie. not ignorable
            if (status == null) {
                status = .;
            }
        }
        return status;
    }
New to GrepCode? Check out our FAQ X