Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.module;
 
 import java.util.*;
 
 
Simple com.fasterxml.jackson.databind.AbstractTypeResolver implementation, which is based on static mapping from abstract super types into sub types (concrete or abstract), but retaining generic parameterization. Can be used for things like specifying which implementation of java.util.Collection to use:
  SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
  // To make all properties declared as Collection, List, to LinkedList
  resolver.addMapping(Collection.class, LinkedList.class);
  resolver.addMapping(List.class, LinkedList.class);
Can also be used as an alternative to per-class annotations when defining concrete implementations; however, only works with abstract types (since this is only called for abstract types)
    extends AbstractTypeResolver
    implements java.io.Serializable
    private static final long serialVersionUID = 8635483102371490919L;

    
Mappings from super types to subtypes
    protected final HashMap<ClassKey,Class<?>> _mappings = new HashMap<ClassKey,Class<?>>();

    
Method for adding a mapping from super type to specific subtype. Arguments will be checked by method, to ensure that superType is abstract (since resolver is never called for concrete classes); as well as to ensure that there is supertype/subtype relationship (to ensure there won't be cycles during resolution).

Parameters:
superType Abstract type to resolve
subType Sub-class of superType, to map superTo to
Returns:
This resolver, to allow chaining of initializations
    public <T> SimpleAbstractTypeResolver addMapping(Class<T> superTypeClass<? extends T> subType)
    {
        // Sanity checks, just in case someone tries to force typing...
        if (superType == subType) {
            throw new IllegalArgumentException("Can not add mapping from class to itself");
        }
        if (!superType.isAssignableFrom(subType)) {
            throw new IllegalArgumentException("Can not add mapping from class "+superType.getName()
                    +" to "+subType.getName()+", as latter is not a subtype of former");
        }
        if (!Modifier.isAbstract(superType.getModifiers())) {
            throw new IllegalArgumentException("Can not add mapping from class "+superType.getName()
                    +" since it is not abstract");
        }
        .put(new ClassKey(superType), subType);
        return this;
    }
    @Override
    public JavaType findTypeMapping(DeserializationConfig configJavaType type)
    {
        // this is the main mapping base, so let's 
        Class<?> src = type.getRawClass();
        Class<?> dst = .get(new ClassKey(src));
        if (dst == null) {
            return null;
        }
        return type.narrowBy(dst);
    }
    
    @Override
    {
        // never materialize anything, so:
        return null;
    }
New to GrepCode? Check out our FAQ X