Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser;
  
  import java.util.*;
  
  
Builder class used for aggregating deserialization information about a POJO, in order to build a com.fasterxml.jackson.databind.JsonDeserializer for deserializing instances.
 
 public class BeanDeserializerBuilder
 {
     /*
     /**********************************************************
     /* General information about POJO
     /**********************************************************
      */
 
     final protected BeanDescription _beanDesc;
 
     final protected boolean _defaultViewInclusion;
     
     /*
     /**********************************************************
     /* Accumulated information about properties
     /**********************************************************
      */
    
    
Properties to deserialize collected so far.
 
     final protected Map<StringSettableBeanProperty_properties
         = new LinkedHashMap<StringSettableBeanProperty>();
    
    
Value injectors for deserialization
 
     protected List<ValueInjector_injectables;
    
    
Back-reference properties this bean contains (if any)
 
     protected HashMap<StringSettableBeanProperty_backRefProperties;

    
Set of names of properties that are recognized but are to be ignored for deserialization purposes (meaning no exception is thrown, value is just skipped).
 
     protected HashSet<String_ignorableProps;
    
    
Object that will handle value instantiation for the bean type.
 
 
     protected ObjectIdReader _objectIdReader;
    
    
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.
 
     protected SettableAnyProperty _anySetter;

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

    
When creating Builder-based deserializers, this indicates method to call on builder to finalize value.
 
     protected AnnotatedMethod _buildMethod;

    
In addition, Builder may have additional configuration
 
     protected JsonPOJOBuilder.Value _builderConfig;
     
     /*
     /**********************************************************
     /* Life-cycle: construction
     /**********************************************************
      */
     
     public BeanDeserializerBuilder(BeanDescription beanDesc,
             DeserializationConfig config)
     { 
         = beanDesc;
    }

    
Copy constructor for sub-classes to use, when constructing custom builder instances
    {
         = src._beanDesc;
         = src._defaultViewInclusion;
         = src._anySetter;
         = src._ignoreAllUnknown;
        // let's make copy of properties
        .putAll(src._properties);
         = _copy(src._backRefProperties);
        // Hmmh. Should we create defensive copies here? For now, not yet
         = src._ignorableProps;        
         = src._valueInstantiator;
         = src._objectIdReader;
        
         = src._buildMethod;
         = src._builderConfig;
    }
    {
        if (src == null) {
            return null;
        }
        return new HashMap<StringSettableBeanProperty>(src);
    }
    
    /*
    /**********************************************************
    /* Life-cycle: state modification (adders, setters)
    /**********************************************************
     */

    
Method for adding a new property or replacing a property.
    public void addOrReplaceProperty(SettableBeanProperty propboolean allowOverride)
    {
        .put(prop.getName(), prop);
    }

    
Method to add a property setter. Will ensure that there is no unexpected override; if one is found will throw a java.lang.IllegalArgumentException.
    public void addProperty(SettableBeanProperty prop)
    {
        SettableBeanProperty old =  .put(prop.getName(), prop);
        if (old != null && old != prop) { // should never occur...
            throw new IllegalArgumentException("Duplicate property '"+prop.getName()+"' for "+.getType());
        }
    }

    
Method called to add a property that represents so-called back reference; reference that "points back" to object that has forward reference to currently built bean.
    public void  addBackReferenceProperty(String referenceNameSettableBeanProperty prop)
    {
        if ( == null) {
             = new HashMap<StringSettableBeanProperty>(4);
        }
        .put(referenceNameprop);
        // also: if we had property with same name, actually remove it
        if ( != null) {
            .remove(prop.getName());
        }
        // ??? 23-Jul-2012, tatu: Should it be included in list of all properties?
        //   For now, won't add, since it is inferred, not explicit...
    }
    @Deprecated // since 2.3
    public void addInjectable(String propNameJavaType propType,
            Annotations contextAnnotationsAnnotatedMember member,
            Object valueId)
    {
        addInjectable(new PropertyName(propName), propTypecontextAnnotationsmembervalueId);
    }
    
    public void addInjectable(PropertyName propNameJavaType propType,
            Annotations contextAnnotationsAnnotatedMember member,
            Object valueId)
    {
        if ( == null) {
             = new ArrayList<ValueInjector>();
        }
        .add(new ValueInjector(propNamepropType,
                contextAnnotationsmembervalueId));
    }
    
    
Method that will add property name as one of properties that can be ignored if not recognized.
    public void addIgnorable(String propName)
    {
        if ( == null) {
             = new HashSet<String>();
        }
        .add(propName);
    }

    
Method called by deserializer factory, when a "creator property" (something that is passed via constructor- or factory method argument; instead of setter or field).

Default implementation does not do anything; we may need to revisit this decision if these properties need to be available through accessors. For now, however, we just have to ensure that we don't try to resolve types that masked setter/field has (see [JACKSON-700] for details).

    public void addCreatorProperty(SettableBeanProperty prop)
    {
        addProperty(prop);
    }
    public void setAnySetter(SettableAnyProperty s)
    {
        if ( != null && s != null) {
            throw new IllegalStateException("_anySetter already set to non-null");
        }
         = s;
    }
    public void setIgnoreUnknownProperties(boolean ignore) {
         = ignore;
    }
    public void setValueInstantiator(ValueInstantiator inst) {
         = inst;
    }
    public void setObjectIdReader(ObjectIdReader r) {
         = r;
    }
    public void setPOJOBuilder(AnnotatedMethod buildMethodJsonPOJOBuilder.Value config) {
         = buildMethod;
         = config;
    }
    
    /*
    /**********************************************************
    /* Public accessors
    /**********************************************************
     */
    
    
Method that allows accessing all properties that this builder currently contains.

Note that properties are returned in order that properties are ordered (explictly, or by rule), which is the serialization order.

        return .values().iterator();
    }

    

Since:
2.3
    public SettableBeanProperty findProperty(PropertyName propertyName) {
        return .get(propertyName.getSimpleName());
    }
    @Deprecated // since 2.3
    public SettableBeanProperty findProperty(String propertyName) {
        return .get(propertyName);
    }

    

Since:
2.3
    public boolean hasProperty(PropertyName propertyName) {
        return findProperty(propertyName) != null;
    }
    
    @Deprecated // since 2.3
    public boolean hasProperty(String propertyName) {
        return findProperty(propertyName) != null;
    }

    

Since:
2.3
        return .remove(name.getSimpleName());
    }
    
    @Deprecated // since 2.3
    public SettableBeanProperty removeProperty(String name) {
        return .remove(name);
    }
    public SettableAnyProperty getAnySetter() {
        return ;
    }
    
        return ;
    }
    public List<ValueInjectorgetInjectables() {
        return ;
    }
    public ObjectIdReader getObjectIdReader() {
        return ;
    }
    public AnnotatedMethod getBuildMethod() {
    	return ;
    }
        return ;
    }
    
    /*
    /**********************************************************
    /* Build method(s)
    /**********************************************************
     */

    
Method for constructing a BeanDeserializer, given all information collected.

NOTE: Signature of this method did unfortunately change between Jackson 2.1 and Jackson 2.2

    public JsonDeserializer<?> build()
    {
        Collection<SettableBeanPropertyprops = .values();
        BeanPropertyMap propertyMap = new BeanPropertyMap(props);
        propertyMap.assignIndexes();
        // view processing must be enabled if:
        // (a) fields are not included by default (when deserializing with view), OR
        // (b) one of properties has view(s) to included in defined
        boolean anyViews = !;
        if (!anyViews) {
            for (SettableBeanProperty prop : props) {
                if (prop.hasViews()) {
                    anyViews = true;
                    break;
                }
            }
        }
        // one more thing: may need to create virtual ObjectId property:
        if ( != null) {
            /* 18-Nov-2012, tatu: May or may not have annotations for id property;
             *   but no easy access. But hard to see id property being optional,
             *   so let's consider required at this point.
             */
            propertyMap = propertyMap.withProperty(prop);
        }
        
        return new BeanDeserializer(this,
                propertyMap,
                anyViews);
    }

    
Alternate build method used when we must be using some form of abstract resolution, usually by using addition Type Id ("polymorphic deserialization")

Since:
2.0
    {
        return new AbstractDeserializer(this);
    }
    
    
Method for constructing a specialized deserializer that uses additional external Builder object during data binding.
    public JsonDeserializer<?> buildBuilderBased(JavaType valueType,
    		String expBuildMethodName)
    {
        // First: validation; must have build method that returns compatible type
        if ( == null) {
            throw new IllegalArgumentException("Builder class "+.getBeanClass().getName()
                    +" does not have build method '"+expBuildMethodName+"()'");
        }
        // also: type of the method must be compatible
        Class<?> rawBuildType = .getRawReturnType();
        if (!valueType.getRawClass().isAssignableFrom(rawBuildType)) {
            throw new IllegalArgumentException("Build method '"+.getFullName()
        			+" has bad return type ("+rawBuildType.getName()
        			+"), not compatible with POJO type ("+valueType.getRawClass().getName()+")");
        }
        // And if so, we can try building the deserializer
        Collection<SettableBeanPropertyprops = .values();
        BeanPropertyMap propertyMap = new BeanPropertyMap(props);
        propertyMap.assignIndexes();
        boolean anyViews = !;
        if (!anyViews) {
            for (SettableBeanProperty prop : props) {
                if (prop.hasViews()) {
                    anyViews = true;
                    break;
                }
            }
        }
        if ( != null) {
            /* 18-Nov-2012, tatu: May or may not have annotations for id property;
             *   but no easy access. But hard to see id property being optional,
             *   so let's consider required at this point.
             */
            ObjectIdValueProperty prop = new ObjectIdValueProperty(,
                    .);
            propertyMap = propertyMap.withProperty(prop);
        }
        
        return new BuilderBasedDeserializer(this,
                propertyMap,
                anyViews);
    }
New to GrepCode? Check out our FAQ X