org.codehaus.jackson.map.type
Class TypeFactory

java.lang.Object
  extended by org.codehaus.jackson.map.type.TypeFactory

public class TypeFactory
extends java.lang.Object

Class that knows how construct JavaType instances, given various inputs.


Field Summary
protected  java.util.HashMap<java.lang.String,JavaType> _commonTypeCache
          To optimize a common use case, we will use a lookup cache to map straight from raw (type erased) Class instances to matching types, for common simple classes.
static TypeFactory instance
           
 
Constructor Summary
protected TypeFactory()
           
 
Method Summary
protected  JavaType _fromArrayType(java.lang.reflect.GenericArrayType type)
           
protected  JavaType _fromClass(java.lang.Class<?> clz)
           
protected  JavaType _fromParamType(java.lang.reflect.ParameterizedType type)
          This method deals with parameterized types, that is, first class generic classes.
 JavaType _fromType(java.lang.reflect.Type type)
          Factory method that can be used if type information is passed as Java typing returned from getGenericXxx methods (usually for a return or argument type).
protected  JavaType _fromVariable(java.lang.reflect.TypeVariable<?> type)
           
protected  JavaType _fromWildcard(java.lang.reflect.WildcardType type)
           
static JavaType fromClass(java.lang.Class<?> clz)
          Factory method that can be used if only type information available is of type Class.
static JavaType fromType(java.lang.reflect.Type type)
          Factory method that can be used if type information is passed as Java typing returned from getGenericXxx methods (usually for a return or argument type).
static JavaType fromTypeReference(TypeReference<?> ref)
          Factory method that can be used if the full generic type has been passed using TypeReference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static final TypeFactory instance

_commonTypeCache

protected final java.util.HashMap<java.lang.String,JavaType> _commonTypeCache
To optimize a common use case, we will use a lookup cache to map straight from raw (type erased) Class instances to matching types, for common simple classes. Not that this lookup Map must not contain anything that could accidentally mask real typed information; specifically, no Map or Collection types are allowed to be added, and similarly only those Array typed where element type can not be a parameterized type. Also: only those classes that are always loaded by the bootstrap class loader (i.e. JDK core classes) can be mapped this way, since we do not include class loader information.

Constructor Detail

TypeFactory

protected TypeFactory()
Method Detail

fromClass

public static JavaType fromClass(java.lang.Class<?> clz)
Factory method that can be used if only type information available is of type Class. This means that there will not be generic type information due to type erasure, but at least it will be possible to recognize array types and non-typed container types. And for other types (primitives/wrappers, beans), this is all that is needed.


fromTypeReference

public static JavaType fromTypeReference(TypeReference<?> ref)
Factory method that can be used if the full generic type has been passed using TypeReference. This only needs to be done if the root type to bind to is generic; but if so, it must be done to get proper typing.


fromType

public static JavaType fromType(java.lang.reflect.Type type)
Factory method that can be used if type information is passed as Java typing returned from getGenericXxx methods (usually for a return or argument type).


_fromClass

protected JavaType _fromClass(java.lang.Class<?> clz)

_fromType

public JavaType _fromType(java.lang.reflect.Type type)
Factory method that can be used if type information is passed as Java typing returned from getGenericXxx methods (usually for a return or argument type).


_fromParamType

protected JavaType _fromParamType(java.lang.reflect.ParameterizedType type)
This method deals with parameterized types, that is, first class generic classes. We actually only care about generics iff they are of type Map or Collection -- otherwise we'll just use the raw type. This because we have no idea how to handle genericized classes in, well, generic fashion. For other types we will then just fall back to using "raw" class information.


_fromArrayType

protected JavaType _fromArrayType(java.lang.reflect.GenericArrayType type)

_fromVariable

protected JavaType _fromVariable(java.lang.reflect.TypeVariable<?> type)

_fromWildcard

protected JavaType _fromWildcard(java.lang.reflect.WildcardType type)