Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.module;
  
  import java.util.*;
  
Simple implementation com.fasterxml.jackson.databind.deser.Deserializers which allows registration of deserializers based on raw (type erased class). It can work well for basic bean and scalar type deserializers, but is not a good fit for handling generic types (like java.util.Maps and java.util.Collections or array types).

Unlike SimpleSerializers, this class does not currently support generic mappings; all mappings must be to exact declared deserialization type.

 
 public class SimpleDeserializers
    implements Deserializersjava.io.Serializable
 {
     private static final long serialVersionUID = -3006673354353448880L;
 
     protected HashMap<ClassKey,JsonDeserializer<?>> _classMappings = null;
 
     /*
     /**********************************************************
     /* Life-cycle, construction and configuring
     /**********************************************************
      */
     
     public SimpleDeserializers() { }

    

Since:
2.1
 
     public SimpleDeserializers(Map<Class<?>,JsonDeserializer<?>> desers) {
         addDeserializers(desers);
     }
     
     public <T> void addDeserializer(Class<T> forClassJsonDeserializer<? extends T> deser)
     {
         ClassKey key = new ClassKey(forClass);
         if ( == null) {
              = new HashMap<ClassKey,JsonDeserializer<?>>();
         }
         .put(keydeser);
     }

    

Since:
2.1
 
     @SuppressWarnings("unchecked")
     public void addDeserializers(Map<Class<?>,JsonDeserializer<?>> desers)
     {
         for (Map.Entry<Class<?>,JsonDeserializer<?>> entry : desers.entrySet()) {
             Class<?> cls = entry.getKey();
             // what a mess... nominal generics safety...
             JsonDeserializer<Objectdeser = (JsonDeserializer<Object>) entry.getValue();
             addDeserializer((Class<Object>) clsdeser);
         }
     }
     
     /*
     /**********************************************************
     /* Serializers implementation
     /**********************************************************
      */
     
     @Override
             DeserializationConfig configBeanDescription beanDesc,
             TypeDeserializer elementTypeDeserializerJsonDeserializer<?> elementDeserializer)
         throws JsonMappingException
     {
         return ( == null) ? null : .get(new ClassKey(type.getRawClass()));
     }
 
     @Override
     public JsonDeserializer<?> findBeanDeserializer(JavaType type,
             DeserializationConfig configBeanDescription beanDesc)
         throws JsonMappingException
     {
         return ( == null) ? null : .get(new ClassKey(type.getRawClass()));
     }
 
     @Override
             DeserializationConfig configBeanDescription beanDesc,
             TypeDeserializer elementTypeDeserializer,
             JsonDeserializer<?> elementDeserializer)
         throws JsonMappingException
     {
         return ( == null) ? null : .get(new ClassKey(type.getRawClass()));
     }
 
     @Override
            DeserializationConfig configBeanDescription beanDesc,
            TypeDeserializer elementTypeDeserializer,
            JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
    {
        return ( == null) ? null : .get(new ClassKey(type.getRawClass()));
    }
    
    @Override
    public JsonDeserializer<?> findEnumDeserializer(Class<?> type,
            DeserializationConfig configBeanDescription beanDesc)
        throws JsonMappingException
    {
        return ( == null) ? null : .get(new ClassKey(type));
    }
    @Override
            DeserializationConfig configBeanDescription beanDesc,
            KeyDeserializer keyDeserializer,
            TypeDeserializer elementTypeDeserializer,
            JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
    {
        return ( == null) ? null : .get(new ClassKey(type.getRawClass()));
    }
    @Override
            DeserializationConfig configBeanDescription beanDesc,
            KeyDeserializer keyDeserializer,
            TypeDeserializer elementTypeDeserializer,
            JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
    {
        return ( == null) ? null : .get(new ClassKey(type.getRawClass()));
    }
    
    @Override
    public JsonDeserializer<?> findTreeNodeDeserializer(Class<? extends JsonNodenodeType,
            DeserializationConfig configBeanDescription beanDesc)
        throws JsonMappingException
    {
        return ( == null) ? null : .get(new ClassKey(nodeType));
    }
New to GrepCode? Check out our FAQ X