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 final class SettableAnyProperty
 {
    
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.
 
     final protected Method _setter;
 
     final protected JavaType _type;
 
 
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
 
     public SettableAnyProperty(BeanProperty propertyAnnotatedMethod setterJavaType type,
             JsonDeserializer<ObjectvalueDeser) {
         this(propertysetter.getAnnotated(), typevalueDeser);
     }
 
     public SettableAnyProperty(BeanProperty propertyMethod rawSetterJavaType type,
             JsonDeserializer<ObjectvalueDeser) {
          = property;
          = type;
          = rawSetter;
          = valueDeser;
     }
 
         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));
     }
 
     public final Object deserialize(JsonParser jpDeserializationContext ctxt)
         throws IOExceptionJsonProcessingException
     {
         JsonToken t = jp.getCurrentToken();
         if (t == .) {
             return null;
         }
         return .deserialize(jpctxt);
     }
    public final 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()+"]"; }
New to GrepCode? Check out our FAQ X