Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.datatype.guava;
  
  
Custom deserializers module offers.

Author(s):
tsaloranta
 
 public class GuavaDeserializers
     extends Deserializers.Base
 {
     @Override
     public JsonDeserializer<?> findBeanDeserializer(final JavaType typeDeserializationConfig config,
             BeanDescription beanDescthrows JsonMappingException {
         Class<?> raw = type.getRawClass();
         if(Optional.class.isAssignableFrom(raw)){
             return new GuavaOptionalDeserializer(type);
         }
         return super.findBeanDeserializer(typeconfigbeanDesc);
     }
    
    
We have plenty of collection types to support...
 
     @Override
             DeserializationConfig configBeanDescription beanDesc,
             TypeDeserializer elementTypeDeserializerJsonDeserializer<?> elementDeserializer)
         throws JsonMappingException
     {
         Class<?> raw = type.getRawClass();
 
         // ImmutableXxx types?
         if (ImmutableCollection.class.isAssignableFrom(raw)) {
             if (ImmutableList.class.isAssignableFrom(raw)) {
                 return new ImmutableListDeserializer(type,
                         elementTypeDeserializerelementDeserializer);
             }
             if (ImmutableMultiset.class.isAssignableFrom(raw)) {
                 // 15-May-2012, pgelinas: There is no ImmutableSortedMultiset
                 // available yet
                 return new ImmutableMultisetDeserializer(typeelementTypeDeserializerelementDeserializer);
             }
             if (ImmutableSet.class.isAssignableFrom(raw)) {
                 // sorted one?
                 if (ImmutableSortedSet.class.isAssignableFrom(raw)) {
                     /* 28-Nov-2010, tatu: With some more work would be able to use other things
                      *   than natural ordering; but that'll have to do for now...
                      */
                     Class<?> elemType = type.getContentType().getRawClass();
                     if (!Comparable.class.isAssignableFrom(elemType)) {
                         throw new IllegalArgumentException("Can not handle ImmutableSortedSet with elements that are not Comparable<?> ("
                                 +raw.getName()+")");
                     }
                     return new ImmutableSortedSetDeserializer(type,
                             elementTypeDeserializerelementDeserializer);
                 }
                 // nah, just regular one
                 return new ImmutableSetDeserializer(type,
                         elementTypeDeserializerelementDeserializer);
             }
             // TODO: make configurable (for now just default blindly to a list)
             return new ImmutableListDeserializer(typeelementTypeDeserializerelementDeserializer);
         }
 
         // Multi-xxx collections?
         if (Multiset.class.isAssignableFrom(raw)) {
             // Quite a few variations...
             if (LinkedHashMultiset.class.isAssignableFrom(raw)) {
                 return new LinkedHashMultisetDeserializer(typeelementTypeDeserializerelementDeserializer);
             }
             if (HashMultiset.class.isAssignableFrom(raw)) {
                 return new HashMultisetDeserializer(typeelementTypeDeserializerelementDeserializer);
             }
             if (EnumMultiset.class.isAssignableFrom(raw)) {
                 // !!! TODO
             }
             if (TreeMultiset.class.isAssignableFrom(raw)) {
                 return new TreeMultisetDeserializer(typeelementTypeDeserializerelementDeserializer);
             }
 
             // TODO: make configurable (for now just default blindly)
             return new HashMultisetDeserializer(typeelementTypeDeserializerelementDeserializer);
         }
 
         return null;
     }

    
A few Map types to support.
    @Override
            DeserializationConfig configBeanDescription beanDesc,
            KeyDeserializer keyDeserializer,
            TypeDeserializer elementTypeDeserializerJsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
    {
        Class<?> raw = type.getRawClass();
        // ImmutableXxxMap types?
        if (ImmutableMap.class.isAssignableFrom(raw)) {
            if (ImmutableSortedMap.class.isAssignableFrom(raw)) {
                return new ImmutableSortedMapDeserializer(typekeyDeserializerelementTypeDeserializer,
                        elementDeserializer);
            }
            if (ImmutableBiMap.class.isAssignableFrom(raw)) {
                return new ImmutableBiMapDeserializer(typekeyDeserializerelementTypeDeserializer,
                        elementDeserializer);
            }
            // Otherwise, plain old ImmutableMap...
            return new ImmutableMapDeserializer(typekeyDeserializerelementTypeDeserializerelementDeserializer);
        }
        // XxxBiMap types?
        if (BiMap.class.isAssignableFrom(raw)) {
            if (EnumBiMap.class.isAssignableFrom(raw)) {
                // !!! TODO
            }
            if (EnumHashBiMap.class.isAssignableFrom(raw)) {
                // !!! TODO
            }
            if (HashBiMap.class.isAssignableFrom(raw)) {
                // !!! TODO
            }
            // !!! TODO default
        }
        return null;
    }
    @Override
            DeserializationConfig configBeanDescription beanDesc,
            KeyDeserializer keyDeserializerTypeDeserializer elementTypeDeserializer,
            JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
    {
        Class<?> raw = type.getRawClass();
        // ImmutableMultimap
        if (ImmutableMultimap.class.isAssignableFrom(raw)) {
            if (ImmutableListMultimap.class.isAssignableFrom(raw)) {
                // !!! TODO
            }
            if (ImmutableSetMultimap.class.isAssignableFrom(raw)) {
                // !!! TODO
            }
            // TODO plain immutable multimap
        }
        if (Multimap.class.isAssignableFrom(raw)) {
            return new MultimapDeserializer(typekeyDeserializerelementTypeDeserializerelementDeserializer);
        }
        if (Table.class.isAssignableFrom(raw)) {
            // !!! TODO
        }
        return null;
    }
New to GrepCode? Check out our FAQ X