Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser.impl;
  
  import java.util.HashMap;
  
  
Object that is used to collect arguments for non-default creator (non-default-constructor, or argument-taking factory method) before creator can be called. Since ordering of JSON properties is not guaranteed, this may require buffering of values other than ones being passed to creator.
 
 public final class PropertyBasedCreator
 {
     protected final ValueInstantiator _valueInstantiator;
    
    
Map that contains property objects for either constructor or factory method (whichever one is null: one property for each parameter for that one), keyed by logical property name
 
     protected final HashMap<StringSettableBeanProperty_properties;

    
Number of properties: usually same as size of _properties, but not necessarily, when we have unnamed injectable properties.
 
     protected final int _propertyCount;
    
    
If some property values must always have a non-null value (like primitive types do), this array contains such default values.
 
     protected final Object[]  _defaultValues;

    
Array that contains properties that expect value to inject, if any; null if no injectable values are expected.
 
     protected final SettableBeanProperty[] _propertiesWithInjectables;
     
     /*
     /**********************************************************
     /* Construction, initialization
     /**********************************************************
      */
     
     protected PropertyBasedCreator(ValueInstantiator valueInstantiator,
             SettableBeanProperty[] creatorPropsObject[] defaultValues)
     {
          = valueInstantiator;
          = new HashMap<StringSettableBeanProperty>();
         SettableBeanProperty[] propertiesWithInjectables = null;
         final int len = creatorProps.length;
          = len;
         for (int i = 0; i < len; ++i) {
             SettableBeanProperty prop = creatorProps[i];
             .put(prop.getName(), prop);
             Object injectableValueId = prop.getInjectableValueId();
             if (injectableValueId != null) {
                 if (propertiesWithInjectables == null) {
                     propertiesWithInjectables = new SettableBeanProperty[len];
                 }
                 propertiesWithInjectables[i] = prop;
             }
         }
          = defaultValues;
          = propertiesWithInjectables;
     }

    
Factory method used for building actual instances: resolves deserializers and checks for "null values".
 
     public static PropertyBasedCreator construct(DeserializationContext ctxt,
             ValueInstantiator valueInstantiatorSettableBeanProperty[] srcProps)
         throws JsonMappingException
     {
         final int len = srcProps.length;
         SettableBeanProperty[] creatorProps = new SettableBeanProperty[len];
         Object[] defaultValues = null;
         for (int i = 0; i < len; ++i) {
             SettableBeanProperty prop = srcProps[i];
             if (!prop.hasValueDeserializer()) {
                 prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop));
             }
             creatorProps[i] = prop;
             // [JACKSON-372]: primitive types need extra care
            // [JACKSON-774]: as do non-default nulls...
            JsonDeserializer<?> deser = prop.getValueDeserializer();
            Object nullValue = (deser == null) ? null : deser.getNullValue();
            if ((nullValue == null) && prop.getType().isPrimitive()) {
                nullValue = ClassUtil.defaultValue(prop.getType().getRawClass());
            }
            if (nullValue != null) {
                if (defaultValues == null) {
                    defaultValues = new Object[len];
                }
                defaultValues[i] = nullValue;
            }
        }
        return new PropertyBasedCreator(valueInstantiatorcreatorPropsdefaultValues);
    }
    
    public void assignDeserializer(SettableBeanProperty propJsonDeserializer<Objectdeser) {
        prop = prop.withValueDeserializer(deser);
        .put(prop.getName(), prop);
    }
    
    /*
    /**********************************************************
    /* Accessors
    /**********************************************************
     */
    
        return .values();
    }
    
        return .get(name);
    }
    /*
    /**********************************************************
    /* Building process
    /**********************************************************
     */

    
Method called when starting to build a bean instance.

Since:
2.1 (added ObjectIdReader parameter -- existed in previous versions without)
            ObjectIdReader oir)
    {
        PropertyValueBuffer buffer = new PropertyValueBuffer(jpctxtoir);
        if ( != null) {
            buffer.inject();
        }
        return buffer;
    }
    public Object build(DeserializationContext ctxtPropertyValueBuffer bufferthrows IOException
    {
        // Object Id to handle?
        bean = buffer.handleIdValue(ctxtbean);
        
        // Anything buffered?
        for (PropertyValue pv = buffer.buffered(); pv != nullpv = pv.next) {
            pv.assign(bean);
        }
        return bean;
    }
New to GrepCode? Check out our FAQ X