Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.deser;
  
  
Complete com.fasterxml.jackson.databind.DeserializationContext implementation that adds extended API for com.fasterxml.jackson.databind.ObjectMapper (and com.fasterxml.jackson.databind.ObjectReader) to call, as well as implements certain parts that base class has left abstract. The remaining abstract methods (createInstance(com.fasterxml.jackson.databind.DeserializationConfig,com.fasterxml.jackson.core.JsonParser,com.fasterxml.jackson.databind.InjectableValues), with(com.fasterxml.jackson.databind.deser.DeserializerFactory)) are left so that custom implementations will properly implement them to return intended subtype.
 
 public abstract class DefaultDeserializationContext
     extends DeserializationContext
     implements java.io.Serializable // since 2.1
 {
     private static final long serialVersionUID = 1L;
 
     protected transient LinkedHashMap<ObjectIdGenerator.IdKeyReadableObjectId_objectIds;
    
    
Constructor that will pass specified deserializer factory and cache: cache may be null (in which case default implementation will be used), factory can not be null
 
         super(dfcache);
     }
     
             DeserializationConfig configJsonParser jpInjectableValues values) {
         super(srcconfigjpvalues);
     }
 
             DeserializerFactory factory) {
         super(srcfactory);
     }
 
     /*
     /**********************************************************
     /* Abstract methods impls, Object Id
     /**********************************************************
      */
 
     @Override
     public ReadableObjectId findObjectId(Object id,
             ObjectIdGenerator<?> generator)
     {
         final ObjectIdGenerator.IdKey key = generator.key(id);
         if ( == null) {
              = new LinkedHashMap<ObjectIdGenerator.IdKeyReadableObjectId>();
         } else {
             ReadableObjectId entry = .get(key);
             if (entry != null) {
                 return entry;
             }
         }
         ReadableObjectId entry = new ReadableObjectId(id);
         .put(keyentry);
         return entry;
     }
 
     @Override
     public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated,
             ObjectIdInfo objectIdInfo)
         throws JsonMappingException
     {
         Class<?> implClass = objectIdInfo.getGeneratorType();
         ObjectIdGenerator<?> gen = (hi == null) ? null : 
             hi.objectIdGeneratorInstance(annotatedimplClass);
         if (gen == null) {
             gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass,
                     .canOverrideAccessModifiers());
         }
         return gen.forScope(objectIdInfo.getScope());
     }
     
     /*
     /**********************************************************
     /* Abstract methods impls, other factory methods
     /**********************************************************
      */
     
     @SuppressWarnings("unchecked")
     @Override
            Object deserDef)
        throws JsonMappingException
    {
        if (deserDef == null) {
            return null;
        }
        JsonDeserializer<?> deser;
        
        if (deserDef instanceof JsonDeserializer) {
            deser = (JsonDeserializer<?>) deserDef;
        } else {
            /* Alas, there's no way to force return type of "either class
             * X or Y" -- need to throw an exception after the fact
             */
            if (!(deserDef instanceof Class)) {
                throw new IllegalStateException("AnnotationIntrospector returned deserializer definition of type "+deserDef.getClass().getName()+"; expected type JsonDeserializer or Class<JsonDeserializer> instead");
            }
            Class<?> deserClass = (Class<?>)deserDef;
            // there are some known "no class" markers to consider too:
            if (deserClass == JsonDeserializer.None.class || deserClass == NoClass.class) {
                return null;
            }
            if (!JsonDeserializer.class.isAssignableFrom(deserClass)) {
                throw new IllegalStateException("AnnotationIntrospector returned Class "+deserClass.getName()+"; expected Class<JsonDeserializer>");
            }
            HandlerInstantiator hi = .getHandlerInstantiator();
            deser = (hi == null) ? null : hi.deserializerInstance(annotateddeserClass);
            if (deser == null) {
                deser = (JsonDeserializer<?>) ClassUtil.createInstance(deserClass,
                        .canOverrideAccessModifiers());
            }
        }
        // First: need to resolve
        if (deser instanceof ResolvableDeserializer) {
            ((ResolvableDeserializerdeser).resolve(this);
        }
        return (JsonDeserializer<Object>) deser;
    }
    @Override
    public final KeyDeserializer keyDeserializerInstance(Annotated annotated,
            Object deserDef)
        throws JsonMappingException
    {
        if (deserDef == null) {
            return null;
        }
        KeyDeserializer deser;
        
        if (deserDef instanceof KeyDeserializer) {
            deser = (KeyDeserializerdeserDef;
        } else {
            if (!(deserDef instanceof Class)) {
                throw new IllegalStateException("AnnotationIntrospector returned key deserializer definition of type "
                        +deserDef.getClass().getName()
                        +"; expected type KeyDeserializer or Class<KeyDeserializer> instead");
            }
            Class<?> deserClass = (Class<?>)deserDef;
            // there are some known "no class" markers to consider too:
            if (deserClass == KeyDeserializer.None.class || deserClass == NoClass.class) {
                return null;
            }
            if (!KeyDeserializer.class.isAssignableFrom(deserClass)) {
                throw new IllegalStateException("AnnotationIntrospector returned Class "+deserClass.getName()
                        +"; expected Class<KeyDeserializer>");
            }
            HandlerInstantiator hi = .getHandlerInstantiator();
            deser = (hi == null) ? null : hi.keyDeserializerInstance(annotateddeserClass);
            if (deser == null) {
                deser = (KeyDeserializer) ClassUtil.createInstance(deserClass,
                        .canOverrideAccessModifiers());
            }
        }
        // First: need to resolve
        if (deser instanceof ResolvableDeserializer) {
            ((ResolvableDeserializerdeser).resolve(this);
        }
        return deser;
    }
    
    /*
    /**********************************************************
    /* Extended API
    /**********************************************************
     */

    
Fluent factory method used for constructing a blueprint instance with different factory
    public abstract DefaultDeserializationContext with(DeserializerFactory factory);
    
    
Method called to create actual usable per-deserialization context instance.
            DeserializationConfig configJsonParser jpInjectableValues values);
    
    /*
    /**********************************************************
    /* And then the concrete implementation class
    /**********************************************************
     */

    
Actual full concrete implementation
    public final static class Impl extends DefaultDeserializationContext
    {
        private static final long serialVersionUID = 1L;

        
Default constructor for a blueprint object, which will use the standard DeserializerCache, given factory.
        public Impl(DeserializerFactory df) {
            super(dfnull);
        }
        protected Impl(Impl src,
                DeserializationConfig configJsonParser jpInjectableValues values) {
            super(srcconfigjpvalues);
        }
        protected Impl(Impl srcDeserializerFactory factory) {
            super(srcfactory);
        }
        
        @Override
                JsonParser jpInjectableValues values) {
            return new Impl(thisconfigjpvalues);
        }
        @Override
        public DefaultDeserializationContext with(DeserializerFactory factory) {
            return new Impl(thisfactory);
        }        
    }
New to GrepCode? Check out our FAQ X