com.fasterxml.jackson.databind.type
Class TypeFactory

java.lang.Object
  extended by com.fasterxml.jackson.databind.type.TypeFactory

public final class TypeFactory
extends Object

Class used for creating concrete JavaType instances, given various inputs.

Instances of this class are accessible using ObjectMapper as well as many objects it constructs (like DeserializationConfig and SerializationConfig)), but usually those objects also expose convenience methods (constructType). So, you can do for example:

   JavaType stringType = mapper.constructType(String.class);
However, more advanced methods are only exposed by factory so that you may need to use:
   JavaType stringCollection = mapper.getTypeFactory().constructCollectionType(List.class, String.class);


Field Summary
protected  HierarchicType _cachedArrayListType
          Lazily constructed copy of type hierarchy from ArrayList to its supertypes.
protected  HierarchicType _cachedHashMapType
          Lazily constructed copy of type hierarchy from HashMap to its supertypes.
protected  TypeModifier[] _modifiers
          Registered TypeModifiers: objects that can change details of JavaType instances factory constructs.
protected  TypeParser _parser
           
protected  LRUMap<ClassKey,JavaType> _typeCache
          Since type resolution can be expensive (specifically when resolving actual generic types), we will use small cache to avoid repetitive resolution of core types
protected static SimpleType CORE_TYPE_BOOL
           
protected static SimpleType CORE_TYPE_INT
           
protected static SimpleType CORE_TYPE_LONG
           
protected static SimpleType CORE_TYPE_STRING
           
protected static TypeFactory instance
          Globally shared singleton.
 
Constructor Summary
protected TypeFactory(TypeParser p, TypeModifier[] mods)
           
 
Method Summary
protected  HierarchicType _arrayListSuperInterfaceChain(HierarchicType current)
           
 JavaType _constructType(Type type, TypeBindings context)
          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  HierarchicType _doFindSuperInterfaceChain(HierarchicType current, Class<?> target)
           
protected  HierarchicType _findSuperClassChain(Type currentType, Class<?> target)
           
protected  HierarchicType _findSuperInterfaceChain(Type currentType, Class<?> target)
           
protected  HierarchicType _findSuperTypeChain(Class<?> subtype, Class<?> supertype)
          Helper method used to find inheritance (implements, extends) path between given types, if one exists (caller generally checks before calling this method).
protected  JavaType _fromArrayType(GenericArrayType type, TypeBindings context)
           
protected  JavaType _fromClass(Class<?> clz, TypeBindings context)
           
protected  JavaType _fromParameterizedClass(Class<?> clz, List<JavaType> paramTypes)
          Method used by TypeParser when generics-aware version is constructed.
protected  JavaType _fromParamType(ParameterizedType type, TypeBindings context)
          This method deals with parameterized types, that is, first class generic classes.
protected  JavaType _fromVariable(TypeVariable<?> type, TypeBindings context)
           
protected  JavaType _fromWildcard(WildcardType type, TypeBindings context)
           
protected  HierarchicType _hashMapSuperInterfaceChain(HierarchicType current)
           
protected  JavaType _resolveVariableViaSubTypes(HierarchicType leafType, String variableName, TypeBindings bindings)
           
protected  JavaType _unknownType()
           
 ArrayType constructArrayType(Class<?> elementType)
          Method for constructing an ArrayType.
 ArrayType constructArrayType(JavaType elementType)
          Method for constructing an ArrayType.
 CollectionLikeType constructCollectionLikeType(Class<?> collectionClass, Class<?> elementClass)
          Method for constructing a CollectionLikeType.
 CollectionLikeType constructCollectionLikeType(Class<?> collectionClass, JavaType elementType)
          Method for constructing a CollectionLikeType.
 CollectionType constructCollectionType(Class<? extends Collection> collectionClass, Class<?> elementClass)
          Method for constructing a CollectionType.
 CollectionType constructCollectionType(Class<? extends Collection> collectionClass, JavaType elementType)
          Method for constructing a CollectionType.
 JavaType constructFromCanonical(String canonical)
          Factory method for constructing a JavaType out of its canonical representation (see ResolvedType.toCanonical()).
 MapLikeType constructMapLikeType(Class<?> mapClass, Class<?> keyClass, Class<?> valueClass)
          Method for constructing a MapLikeType instance
 MapLikeType constructMapLikeType(Class<?> mapClass, JavaType keyType, JavaType valueType)
          Method for constructing a MapLikeType instance
 MapType constructMapType(Class<? extends Map> mapClass, Class<?> keyClass, Class<?> valueClass)
          Method for constructing a MapType instance
 MapType constructMapType(Class<? extends Map> mapClass, JavaType keyType, JavaType valueType)
          Method for constructing a MapType instance
 JavaType constructParametricType(Class<?> parametrized, Class<?>... parameterClasses)
          Factory method for constructing JavaType that represents a parameterized type.
 JavaType constructParametricType(Class<?> parametrized, JavaType... parameterTypes)
          Factory method for constructing JavaType that represents a parameterized type.
 CollectionLikeType constructRawCollectionLikeType(Class<?> collectionClass)
          Method that can be used to construct "raw" Collection-like type; meaning that its parameterization is unknown.
 CollectionType constructRawCollectionType(Class<? extends Collection> collectionClass)
          Method that can be used to construct "raw" Collection type; meaning that its parameterization is unknown.
 MapLikeType constructRawMapLikeType(Class<?> mapClass)
          Method that can be used to construct "raw" Map-like type; meaning that its parameterization is unknown.
 MapType constructRawMapType(Class<? extends Map> mapClass)
          Method that can be used to construct "raw" Map type; meaning that its parameterization is unknown.
 JavaType constructSimpleType(Class<?> rawType, JavaType[] parameterTypes)
          Method for constructing a type instance with specified parameterization.
 JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
          Factory method for creating a subtype of given base type, as defined by specified subclass; but retaining generic type information if any.
 JavaType constructType(Type type)
           
 JavaType constructType(Type type, Class<?> context)
           
 JavaType constructType(Type type, JavaType context)
           
 JavaType constructType(com.fasterxml.jackson.core.type.TypeReference<?> typeRef)
           
 JavaType constructType(Type type, TypeBindings bindings)
           
static TypeFactory defaultInstance()
          Method used to access the globally shared instance, which has no custom configuration.
 JavaType[] findTypeParameters(Class<?> clz, Class<?> expType)
           
 JavaType[] findTypeParameters(Class<?> clz, Class<?> expType, TypeBindings bindings)
           
 JavaType[] findTypeParameters(JavaType type, Class<?> expType)
          Method that is to figure out actual type parameters that given class binds to generic types defined by given (generic) interface or class.
static Class<?> rawClass(Type t)
          Static helper method that can be called to figure out type-erased call for given JDK type.
 JavaType uncheckedSimpleType(Class<?> cls)
          Method that will force construction of a simple type, without trying to check for more specialized types.
static JavaType unknownType()
          Method for constructing a marker type that indicates missing generic type information, which is handled same as simple type for java.lang.Object.
 TypeFactory withModifier(TypeModifier mod)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

protected static final TypeFactory instance
Globally shared singleton. Not accessed directly; non-core code should use per-ObjectMapper instance (via configuration objects). Core Jackson code uses defaultInstance() for accessing it.


CORE_TYPE_STRING

protected static final SimpleType CORE_TYPE_STRING

CORE_TYPE_BOOL

protected static final SimpleType CORE_TYPE_BOOL

CORE_TYPE_INT

protected static final SimpleType CORE_TYPE_INT

CORE_TYPE_LONG

protected static final SimpleType CORE_TYPE_LONG

_typeCache

protected final LRUMap<ClassKey,JavaType> _typeCache
Since type resolution can be expensive (specifically when resolving actual generic types), we will use small cache to avoid repetitive resolution of core types


_cachedHashMapType

protected HierarchicType _cachedHashMapType
Lazily constructed copy of type hierarchy from HashMap to its supertypes.


_cachedArrayListType

protected HierarchicType _cachedArrayListType
Lazily constructed copy of type hierarchy from ArrayList to its supertypes.


_modifiers

protected final TypeModifier[] _modifiers
Registered TypeModifiers: objects that can change details of JavaType instances factory constructs.


_parser

protected final TypeParser _parser
Constructor Detail

TypeFactory

protected TypeFactory(TypeParser p,
                      TypeModifier[] mods)
Method Detail

withModifier

public TypeFactory withModifier(TypeModifier mod)

defaultInstance

public static TypeFactory defaultInstance()
Method used to access the globally shared instance, which has no custom configuration. Used by ObjectMapper to get the default factory when constructed.


unknownType

public static JavaType unknownType()
Method for constructing a marker type that indicates missing generic type information, which is handled same as simple type for java.lang.Object.


rawClass

public static Class<?> rawClass(Type t)
Static helper method that can be called to figure out type-erased call for given JDK type. It can be called statically since type resolution process can never change actual type-erased class; thereby static default instance is used for determination.


constructSpecializedType

public JavaType constructSpecializedType(JavaType baseType,
                                         Class<?> subclass)
Factory method for creating a subtype of given base type, as defined by specified subclass; but retaining generic type information if any. Can be used, for example, to get equivalent of "HashMap<String,Integer>" from "Map<String,Integer>" by giving HashMap.class as subclass.


constructFromCanonical

public JavaType constructFromCanonical(String canonical)
                                throws IllegalArgumentException
Factory method for constructing a JavaType out of its canonical representation (see ResolvedType.toCanonical()).

Parameters:
canonical - Canonical string representation of a type
Throws:
IllegalArgumentException - If canonical representation is malformed, or class that type represents (including its generic parameters) is not found

findTypeParameters

public JavaType[] findTypeParameters(JavaType type,
                                     Class<?> expType)
Method that is to figure out actual type parameters that given class binds to generic types defined by given (generic) interface or class. This could mean, for example, trying to figure out key and value types for Map implementations.

Parameters:
type - Sub-type (leaf type) that implements expType

findTypeParameters

public JavaType[] findTypeParameters(Class<?> clz,
                                     Class<?> expType)

findTypeParameters

public JavaType[] findTypeParameters(Class<?> clz,
                                     Class<?> expType,
                                     TypeBindings bindings)

constructType

public JavaType constructType(Type type)

constructType

public JavaType constructType(Type type,
                              TypeBindings bindings)

constructType

public JavaType constructType(com.fasterxml.jackson.core.type.TypeReference<?> typeRef)

constructType

public JavaType constructType(Type type,
                              Class<?> context)

constructType

public JavaType constructType(Type type,
                              JavaType context)

_constructType

public JavaType _constructType(Type type,
                               TypeBindings context)
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).


constructArrayType

public ArrayType constructArrayType(Class<?> elementType)
Method for constructing an ArrayType.

NOTE: type modifiers are NOT called on array type itself; but are called for element type (and other contained types)


constructArrayType

public ArrayType constructArrayType(JavaType elementType)
Method for constructing an ArrayType.

NOTE: type modifiers are NOT called on array type itself; but are called for contained types.


constructCollectionType

public CollectionType constructCollectionType(Class<? extends Collection> collectionClass,
                                              Class<?> elementClass)
Method for constructing a CollectionType.

NOTE: type modifiers are NOT called on Collection type itself; but are called for contained types.


constructCollectionType

public CollectionType constructCollectionType(Class<? extends Collection> collectionClass,
                                              JavaType elementType)
Method for constructing a CollectionType.

NOTE: type modifiers are NOT called on Collection type itself; but are called for contained types.


constructCollectionLikeType

public CollectionLikeType constructCollectionLikeType(Class<?> collectionClass,
                                                      Class<?> elementClass)
Method for constructing a CollectionLikeType.

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructCollectionLikeType

public CollectionLikeType constructCollectionLikeType(Class<?> collectionClass,
                                                      JavaType elementType)
Method for constructing a CollectionLikeType.

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructMapType

public MapType constructMapType(Class<? extends Map> mapClass,
                                JavaType keyType,
                                JavaType valueType)
Method for constructing a MapType instance

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructMapType

public MapType constructMapType(Class<? extends Map> mapClass,
                                Class<?> keyClass,
                                Class<?> valueClass)
Method for constructing a MapType instance

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructMapLikeType

public MapLikeType constructMapLikeType(Class<?> mapClass,
                                        JavaType keyType,
                                        JavaType valueType)
Method for constructing a MapLikeType instance

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructMapLikeType

public MapLikeType constructMapLikeType(Class<?> mapClass,
                                        Class<?> keyClass,
                                        Class<?> valueClass)
Method for constructing a MapLikeType instance

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructSimpleType

public JavaType constructSimpleType(Class<?> rawType,
                                    JavaType[] parameterTypes)
Method for constructing a type instance with specified parameterization.


uncheckedSimpleType

public JavaType uncheckedSimpleType(Class<?> cls)
Method that will force construction of a simple type, without trying to check for more specialized types.

NOTE: no type modifiers are called on type either, so calling this method should only be used if caller really knows what it's doing...


constructParametricType

public JavaType constructParametricType(Class<?> parametrized,
                                        Class<?>... parameterClasses)
Factory method for constructing JavaType that represents a parameterized type. For example, to represent type List<Set<Integer>>, you could call
  TypeFactory.parametricType(List.class, Integer.class);

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructParametricType

public JavaType constructParametricType(Class<?> parametrized,
                                        JavaType... parameterTypes)
Factory method for constructing JavaType that represents a parameterized type. For example, to represent type List<Set<Integer>>, you could call
  JavaType inner = TypeFactory.parametricType(Set.class, Integer.class);
  TypeFactory.parametricType(List.class, inner);

NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.


constructRawCollectionType

public CollectionType constructRawCollectionType(Class<? extends Collection> collectionClass)
Method that can be used to construct "raw" Collection type; meaning that its parameterization is unknown. This is similar to using Object.class parameterization, and is equivalent to calling:
  typeFactory.constructCollectionType(collectionClass, typeFactory.unknownType());

This method should only be used if parameterization is completely unavailable.


constructRawCollectionLikeType

public CollectionLikeType constructRawCollectionLikeType(Class<?> collectionClass)
Method that can be used to construct "raw" Collection-like type; meaning that its parameterization is unknown. This is similar to using Object.class parameterization, and is equivalent to calling:
  typeFactory.constructCollectionLikeType(collectionClass, typeFactory.unknownType());

This method should only be used if parameterization is completely unavailable.


constructRawMapType

public MapType constructRawMapType(Class<? extends Map> mapClass)
Method that can be used to construct "raw" Map type; meaning that its parameterization is unknown. This is similar to using Object.class parameterization, and is equivalent to calling:
  typeFactory.constructMapType(collectionClass, typeFactory.unknownType(), typeFactory.unknownType());

This method should only be used if parameterization is completely unavailable.


constructRawMapLikeType

public MapLikeType constructRawMapLikeType(Class<?> mapClass)
Method that can be used to construct "raw" Map-like type; meaning that its parameterization is unknown. This is similar to using Object.class parameterization, and is equivalent to calling:
  typeFactory.constructMapLikeType(collectionClass, typeFactory.unknownType(), typeFactory.unknownType());

This method should only be used if parameterization is completely unavailable.


_fromClass

protected JavaType _fromClass(Class<?> clz,
                              TypeBindings context)
Parameters:
context - Mapping of formal parameter declarations (for generic types) into actual types

_fromParameterizedClass

protected JavaType _fromParameterizedClass(Class<?> clz,
                                           List<JavaType> paramTypes)
Method used by TypeParser when generics-aware version is constructed.


_fromParamType

protected JavaType _fromParamType(ParameterizedType type,
                                  TypeBindings context)
This method deals with parameterized types, that is, first class generic classes.


_fromArrayType

protected JavaType _fromArrayType(GenericArrayType type,
                                  TypeBindings context)

_fromVariable

protected JavaType _fromVariable(TypeVariable<?> type,
                                 TypeBindings context)

_fromWildcard

protected JavaType _fromWildcard(WildcardType type,
                                 TypeBindings context)

_resolveVariableViaSubTypes

protected JavaType _resolveVariableViaSubTypes(HierarchicType leafType,
                                               String variableName,
                                               TypeBindings bindings)

_unknownType

protected JavaType _unknownType()

_findSuperTypeChain

protected HierarchicType _findSuperTypeChain(Class<?> subtype,
                                             Class<?> supertype)
Helper method used to find inheritance (implements, extends) path between given types, if one exists (caller generally checks before calling this method). Returned type represents given subtype, with supertype linkage extending to supertype.


_findSuperClassChain

protected HierarchicType _findSuperClassChain(Type currentType,
                                              Class<?> target)

_findSuperInterfaceChain

protected HierarchicType _findSuperInterfaceChain(Type currentType,
                                                  Class<?> target)

_doFindSuperInterfaceChain

protected HierarchicType _doFindSuperInterfaceChain(HierarchicType current,
                                                    Class<?> target)

_hashMapSuperInterfaceChain

protected HierarchicType _hashMapSuperInterfaceChain(HierarchicType current)

_arrayListSuperInterfaceChain

protected HierarchicType _arrayListSuperInterfaceChain(HierarchicType current)


Copyright © 2012 fasterxml.com. All Rights Reserved.