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.
 
 public class AbstractDeserializer
     extends JsonDeserializer<Object>
     implements java.io.Serializable
 {
     private static final long serialVersionUID = -3010349050434697698L;
 
     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);
     }
 
     protected AbstractDeserializer(BeanDescription beanDesc)
     {
          = beanDesc.getType();
          = null;
          = null;
         Class<?> cls = .getRawClass();
          = cls.isAssignableFrom(String.class);
          = (cls == .) || cls.isAssignableFrom(Boolean.class);
          = (cls == .) || cls.isAssignableFrom(Integer.class);
          = (cls == .) || cls.isAssignableFrom(Double.class);
     }
    
    
Factory method used when constructing instances for non-POJO types, like java.util.Maps.

Since:
2.3
 
     public static AbstractDeserializer constructForNonPOJO(BeanDescription beanDesc)
     {
         return new AbstractDeserializer(beanDesc);
     }
     
     /*
     /**********************************************************
     /* Public accessors
     /**********************************************************
      */
 
     @Override
     public Class<?> handledType() {
         return .getRawClass();
     }
     
     @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.
    @Override
    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.
         */
        /* 21-Sep-2013, tatu: It may seem odd that I'm not using a switch here.
         *   But turns out that a switch on an enum generates an inner class...
         *   crazy! So this is to avoid that, simply since new class weighs about 1kB
         *   after compression.
         */
        final JsonToken t = jp.getCurrentToken();
        if (t.isScalarValue()) {
            if (t == .) {
                if () {
                    return jp.getText();
                }
            } else if (t == .) {
                if () {
                    return jp.getIntValue();
                }
            } else if (t == .) {
                if () {
                    return Double.valueOf(jp.getDoubleValue());
                }
            } else if (t == .) {
                if () {
                    return .;
                }
            } else if (t == .) {
                if () {
                    return .;
                }
            }
        }
        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 = .readObjectReference(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