Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser;
  
  
Class that represents a "wildcard" set method which can be used to generically set values of otherwise unmapped (aka "unknown") properties read from Json content.

!!! Note: might make sense to refactor to share some code with SettableBeanProperty?

 
 public class SettableAnyProperty
     implements java.io.Serializable
 {
     private static final long serialVersionUID = 1L;
    
    
Method used for setting "any" properties, along with annotation information. Retained to allow contextualization of any properties.
 
     final protected BeanProperty _property;
    
    
Physical JDK object used for assigning properties.

NOTE: must be marked transient since it is not serializable, in case these are to be serialized

 
     protected final transient Method _setter;
 
     protected final JavaType _type;
 
 
     protected final TypeDeserializer _valueTypeDeserializer;
     
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
 
     @Deprecated // since 2.3
     public SettableAnyProperty(BeanProperty propertyAnnotatedMethod setterJavaType type,
             JsonDeserializer<ObjectvalueDeser) {
         this(propertysettertypevalueDesernull);
     }
 
     public SettableAnyProperty(BeanProperty propertyAnnotatedMethod setterJavaType type,
             JsonDeserializer<ObjectvalueDeserTypeDeserializer typeDeser)
     {
         this(propertysetter.getAnnotated(), typevalueDesertypeDeser);
     }
     
     @Deprecated // since 2.3
     public SettableAnyProperty(BeanProperty propertyMethod rawSetterJavaType type,
             JsonDeserializer<ObjectvalueDeser) {
         this(propertyrawSettertypevalueDesernull);
     }
     
     public SettableAnyProperty(BeanProperty propertyMethod rawSetterJavaType type,
             JsonDeserializer<ObjectvalueDeserTypeDeserializer typeDeser)
     {
          = property;
          = type;
          = rawSetter;
          = valueDeser;
          = typeDeser;
     }
 
         return new SettableAnyProperty(,
                 deser);
     }
     
     /*
     /**********************************************************
     /* Public API, accessors
     /**********************************************************
      */
 
     public BeanProperty getProperty() { return ; }
     
     public boolean hasValueDeserializer() { return ( != null); }
 
     public JavaType getType() { return ; }
 
     /*
     /**********************************************************
     /* Public API, deserialization
     /**********************************************************
      */
    
    
Method called to deserialize appropriate value, given parser (and context), and set it using appropriate method (a setter method).
    public final void deserializeAndSet(JsonParser jpDeserializationContext ctxt,
                                        Object instanceString propName)
        throws IOExceptionJsonProcessingException
    {
        set(instancepropNamedeserialize(jpctxt));
    }
        throws IOExceptionJsonProcessingException
    {
        JsonToken t = jp.getCurrentToken();
        if (t == .) {
            return null;
        }
        if ( != null) {
            return .deserializeWithType(jpctxt);
        }
        return .deserialize(jpctxt);
    }
    public void set(Object instanceString propNameObject value)
        throws IOException
    {
        try {
            .invoke(instancepropNamevalue);
        } catch (Exception e) {
            _throwAsIOE(epropNamevalue);
        }
    }
    /*
    /**********************************************************
    /* Helper methods
    /**********************************************************
     */

    

Parameters:
e Exception to re-throw or wrap
propName Name of property (from Json input) to set
value Value of the property
    protected void _throwAsIOE(Exception eString propNameObject value)
        throws IOException
    {
        if (e instanceof IllegalArgumentException) {
            String actType = (value == null) ? "[NULL]" : value.getClass().getName();
            StringBuilder msg = new StringBuilder("Problem deserializing \"any\" property '").append(propName);
            msg.append("' of class "+getClassName()+" (expected type: ").append();
            msg.append("; actual type: ").append(actType).append(")");
            String origMsg = e.getMessage();
            if (origMsg != null) {
                msg.append(", problem: ").append(origMsg);
            } else {
                msg.append(" (no error message provided)");
            }
            throw new JsonMappingException(msg.toString(), nulle);
        }
        if (e instanceof IOException) {
            throw (IOExceptione;
        }
        if (e instanceof RuntimeException) {
            throw (RuntimeExceptione;
        }
        // let's wrap the innermost problem
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        throw new JsonMappingException(t.getMessage(), nullt);
    }
    private String getClassName() { return .getDeclaringClass().getName(); }
    @Override public String toString() { return "[any property on class "+getClassName()+"]"; }
    /*
    /**********************************************************
    /* JDK serialization handling
    /**********************************************************
     */
    // TODO (2.3): handle restoring of reference to any-setter method
    
/*
    Object readResolve() {
        return new SettableAnyProperty(this, _annotated.getAnnotated());
    }
    */
New to GrepCode? Check out our FAQ X