Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser;
  
  import java.util.*;
  
Deserializer only used for abstract types used as placeholders during polymorphic type handling deserialization. If so, there is no real deserializer associated with nominal type, just com.fasterxml.jackson.databind.jsontype.TypeDeserializer; and any calls that do not pass such resolver will result in an error.

Author(s):
tatu
 
 public class AbstractDeserializer
     extends JsonDeserializer<Object>
 {
     protected final JavaType _baseType;
 
     protected final ObjectIdReader _objectIdReader;
 
     protected final Map<StringSettableBeanProperty_backRefProperties;
     
     // support for "native" types, which require special care:
     
     protected final boolean _acceptString;
     protected final boolean _acceptBoolean;
     protected final boolean _acceptInt;
     protected final boolean _acceptDouble;
     
             BeanDescription beanDescMap<StringSettableBeanPropertybackRefProps)
     {
          = beanDesc.getType();
          = builder.getObjectIdReader();
          = backRefProps;
         Class<?> cls = .getRawClass();
          = cls.isAssignableFrom(String.class);
          = (cls == .) || cls.isAssignableFrom(Boolean.class);
          = (cls == .) || cls.isAssignableFrom(Integer.class);
          = (cls == .) || cls.isAssignableFrom(Double.class);
     }
 
     /*
     /**********************************************************
     /* Public accessors
     /**********************************************************
      */
 
     @Override
     public boolean isCachable() { return true; }
    
    
Overridden to return true for those instances that are handling value for which Object Identity handling is enabled (either via value type or referring property).
 
     @Override
     public ObjectIdReader getObjectIdReader() {
         return ;
     }

    
Method called by BeanDeserializer to resolve back reference part of managed references.
 
     public SettableBeanProperty findBackReference(String logicalName)
     {
         return ( == null) ? null : .get(logicalName);
     }
     
     /*
     /**********************************************************
     /* Deserializer implementation
     /**********************************************************
      */
     
     @Override
             TypeDeserializer typeDeserializer)
         throws IOExceptionJsonProcessingException
     {
         // Hmmh. One tricky question; for scalar, is it an Object Id, or "Natural" type?
 
         // for now, prefer Object Id:
         if ( != null) {
             JsonToken t = jp.getCurrentToken();
             // should be good enough check; we only care about Strings, integral numbers:
             if (t != null && t.isScalarValue()) {
                 return _deserializeFromObjectId(jpctxt);
             }
         }
         
         // First: support "natural" values (which are always serialized without type info!)
        Object result = _deserializeIfNatural(jpctxt);
        if (result != null) {
            return result;
        }
        return typeDeserializer.deserializeTypedFromObject(jpctxt);
    }
    @Override
            throws IOExceptionJsonProcessingException
    {
        // This method should never be called...
        throw ctxt.instantiationException(.getRawClass(),
                "abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information");
    }
    /*
    /**********************************************************
    /* Internal methods
    /**********************************************************
     */
    
        throws IOExceptionJsonProcessingException
    {
        /* As per [JACKSON-417], there is a chance we might be "natural" types
         * (String, Boolean, Integer, Double), which do not include any type information...
         * Care must be taken to only return this if return type matches, however.
         * Finally, we may have to consider possibility of custom handlers for
         * these values: but for now this should work ok.
         */
        switch (jp.getCurrentToken()) {
        case :
            if () {
                return jp.getText();
            }
            break;
        case :
            if () {
                return jp.getIntValue();
            }
            break;
        case :
            if () {
                return Double.valueOf(jp.getDoubleValue());
            }
            break;
        case :
            if () {
                return .;
            }
            break;
        case :
            if () {
                return .;
            }
            break;
        }
        return null;
    }

    
Method called in cases where it looks like we got an Object Id to parse and use as a reference.
        throws IOExceptionJsonProcessingException
    {
        Object id = ..deserialize(jpctxt);
        ReadableObjectId roid = ctxt.findObjectId(id.);
        // do we have it resolved?
        Object pojo = roid.item;
        if (pojo == null) { // not yet; should wait...
            throw new IllegalStateException("Could not resolve Object Id ["+id+"] -- unresolved forward-reference?");
        }
        return pojo;
    }
New to GrepCode? Check out our FAQ X