Class TypeFactory
JavaType instances,
given various inputs.
As of Jackson 1.8, usage should be done using instance configured
via ObjectMapper (and exposed through
DeserializationConfig and
SerializationConfig).
However, old static-singleton access methods are supported as well; however,
using those may cause issues with extension modules that register
"type enchancers".
Typical usage pattern before Jackson 1.8 was to statically import factory methods
of this class, to allow convenient instantiation of structured
types, especially Collection and Map types
to represent generic types. For example
mapType(String.class, Integer.class)to represent
Map<String,Integer>This is an alternative to using
TypeReference that would
be something like
new TypeReference<Map<String,Integer>>() { }
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HierarchicTypeLazily constructed copy of type hierarchy fromArrayListto its supertypes.protected HierarchicTypeLazily constructed copy of type hierarchy fromHashMapto its supertypes.protected final TypeModifier[]RegisteredTypeModifiers: objects that can change details ofJavaTypeinstances factory constructs.protected final TypeParserstatic final TypeFactoryDeprecated.As of 1.8, should use a per-ObjectMapper instance instead of global singleton -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected HierarchicType_constructType(Type type, TypeBindings context) Factory method that can be used if type information is passed as Java typing returned fromgetGenericXxxmethods (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 byTypeParserwhen 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 HierarchicTypeprotected JavaType_resolveVariableViaSubTypes(HierarchicType leafType, String variableName, TypeBindings bindings) protected JavaTypestatic JavaTypeDeprecated.static JavaTypeDeprecated.static JavaTypecollectionType(Class<? extends Collection> collectionType, Class<?> elementType) Deprecated.static JavaTypecollectionType(Class<? extends Collection> collectionType, JavaType elementType) Deprecated.constructArrayType(Class<?> elementType) Method for constructing anArrayType.constructArrayType(JavaType elementType) Method for constructing anArrayType.constructCollectionLikeType(Class<?> collectionClass, Class<?> elementClass) Method for constructing aCollectionLikeType.constructCollectionLikeType(Class<?> collectionClass, JavaType elementType) Method for constructing aCollectionLikeType.constructCollectionType(Class<? extends Collection> collectionClass, Class<?> elementClass) Method for constructing aCollectionType.constructCollectionType(Class<? extends Collection> collectionClass, JavaType elementType) Method for constructing aCollectionType.constructFromCanonical(String canonical) Factory method for constructing aJavaTypeout of its canonical representation (seeJavaType.toCanonical()).constructMapLikeType(Class<?> mapClass, Class<?> keyClass, Class<?> valueClass) Method for constructing aMapLikeTypeinstanceconstructMapLikeType(Class<?> mapClass, JavaType keyType, JavaType valueType) Method for constructing aMapLikeTypeinstanceconstructMapType(Class<? extends Map> mapClass, Class<?> keyClass, Class<?> valueClass) Method for constructing aMapTypeinstanceconstructMapType(Class<? extends Map> mapClass, JavaType keyType, JavaType valueType) Method for constructing aMapTypeinstanceconstructParametricType(Class<?> parametrized, Class<?>... parameterClasses) Factory method for constructingJavaTypethat represents a parameterized type.constructParametricType(Class<?> parametrized, JavaType... parameterTypes) Factory method for constructingJavaTypethat represents a parameterized type.constructRawCollectionLikeType(Class<?> collectionClass) Method that can be used to construct "raw" Collection-like type; meaning that its parameterization is unknown.constructRawCollectionType(Class<? extends Collection> collectionClass) Method that can be used to construct "raw" Collection type; meaning that its parameterization is unknown.constructRawMapLikeType(Class<?> mapClass) Method that can be used to construct "raw" Map-like type; meaning that its parameterization is unknown.constructRawMapType(Class<? extends Map> mapClass) Method that can be used to construct "raw" Map type; meaning that its parameterization is unknown.constructSimpleType(Class<?> rawType, JavaType[] parameterTypes) Method for constructing a type instance with specified parameterization.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.constructType(Type type) constructType(Type type, Class<?> context) constructType(Type type, TypeBindings bindings) constructType(Type type, JavaType context) constructType(TypeReference<?> typeRef) static TypeFactoryMethod used to access the globally shared instance, which has no custom configuration.static JavaTypefastSimpleType(Class<?> cls) Deprecated.static JavaType[]findParameterTypes(Class<?> clz, Class<?> expType) Deprecated.static JavaType[]findParameterTypes(Class<?> clz, Class<?> expType, TypeBindings bindings) Deprecated.static JavaType[]findParameterTypes(JavaType type, Class<?> expType) Deprecated.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 JavaTypefromCanonical(String canonical) static JavaTypeDeprecated.Usetype(Type)insteadstatic JavaTypeDeprecated.Usetype(Type)insteadstatic JavaTypefromTypeReference(TypeReference<?> ref) Deprecated.Usetype(Type)insteadstatic JavaTypeDeprecated.static JavaTypeDeprecated.static JavaTypeparametricType(Class<?> parametrized, Class<?>... parameterClasses) Deprecated.static JavaTypeparametricType(Class<?> parametrized, JavaType... parameterTypes) Deprecated.static Class<?> static JavaTypespecialize(JavaType baseType, Class<?> subclass) Deprecated.static JavaTypeDeprecated.static JavaTypeDeprecated.static JavaTypetype(Type type, TypeBindings bindings) Deprecated.static JavaTypeDeprecated.static JavaTypetype(TypeReference<?> ref) Deprecated.uncheckedSimpleType(Class<?> cls) Method that will force construction of a simple type, without trying to check for more specialized types.static JavaTypeMethod for constructing a marker type that indicates missing generic type information, which is handled same as simple type forjava.lang.Object.withModifier(TypeModifier mod)
-
Field Details
-
instance
Deprecated.As of 1.8, should use a per-ObjectMapper instance instead of global singletonGlobally shared singleton. Should never be accessed directly; non-core code should use per-ObjectMapper instance (via configuration objects). Core Jackson code usesdefaultInstance()for accessing it. -
_modifiers
RegisteredTypeModifiers: objects that can change details ofJavaTypeinstances factory constructs.- Since:
- 1.8
-
_parser
-
_cachedHashMapType
Lazily constructed copy of type hierarchy fromHashMapto its supertypes.- Since:
- 1.9
-
_cachedArrayListType
Lazily constructed copy of type hierarchy fromArrayListto its supertypes.- Since:
- 1.9
-
-
Constructor Details
-
TypeFactory
-
-
Method Details
-
withModifier
-
defaultInstance
Method used to access the globally shared instance, which has no custom configuration. Used byObjectMapperto get the default factory when constructed.- Since:
- 1.8
-
unknownType
Method for constructing a marker type that indicates missing generic type information, which is handled same as simple type forjava.lang.Object.- Since:
- 1.8
-
rawClass
-
type
Deprecated. -
type
Deprecated. -
type
Deprecated. -
type
Deprecated. -
type
Deprecated. -
arrayType
Deprecated. -
arrayType
Deprecated. -
collectionType
@Deprecated public static JavaType collectionType(Class<? extends Collection> collectionType, Class<?> elementType) Deprecated. -
collectionType
@Deprecated public static JavaType collectionType(Class<? extends Collection> collectionType, JavaType elementType) Deprecated. -
mapType
-
mapType
-
parametricType
@Deprecated public static JavaType parametricType(Class<?> parametrized, Class<?>... parameterClasses) Deprecated. -
parametricType
@Deprecated public static JavaType parametricType(Class<?> parametrized, JavaType... parameterTypes) Deprecated. -
fromCanonical
- Throws:
IllegalArgumentException
-
specialize
Deprecated. -
fastSimpleType
Deprecated. -
findParameterTypes
Deprecated. -
findParameterTypes
@Deprecated public static JavaType[] findParameterTypes(Class<?> clz, Class<?> expType, TypeBindings bindings) Deprecated. -
findParameterTypes
Deprecated. -
fromClass
Deprecated.Usetype(Type)insteadFactory method that can be used if only type information available is of typeClass. 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
Deprecated.Usetype(Type)insteadFactory method that can be used if the full generic type has been passed usingTypeReference. 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
Deprecated.Usetype(Type)insteadFactory method that can be used if type information is passed as Java typing returned fromgetGenericXxxmethods (usually for a return or argument type). -
constructSpecializedType
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 "Mapinvalid input: '<String',Integer>" by givingHashMap.classas subclass. -
constructFromCanonical
Factory method for constructing aJavaTypeout of its canonical representation (seeJavaType.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- Since:
- 1.8
-
findTypeParameters
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 implementsexpType- Since:
- 1.6
-
findTypeParameters
-
findTypeParameters
-
constructType
-
constructType
-
constructType
-
constructType
-
constructType
-
_constructType
Factory method that can be used if type information is passed as Java typing returned fromgetGenericXxxmethods (usually for a return or argument type). -
constructArrayType
-
constructArrayType
-
constructCollectionType
public CollectionType constructCollectionType(Class<? extends Collection> collectionClass, Class<?> elementClass) Method for constructing aCollectionType.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 aCollectionType.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 aCollectionLikeType.NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
- Since:
- 1.8
-
constructCollectionLikeType
public CollectionLikeType constructCollectionLikeType(Class<?> collectionClass, JavaType elementType) Method for constructing aCollectionLikeType.NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
- Since:
- 1.8
-
constructMapType
-
constructMapType
-
constructMapLikeType
Method for constructing aMapLikeTypeinstanceNOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
- Since:
- 1.8
-
constructMapLikeType
Method for constructing aMapLikeTypeinstanceNOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
- Since:
- 1.8
-
constructSimpleType
-
uncheckedSimpleType
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...
- Since:
- 1.8
-
constructParametricType
Factory method for constructingJavaTypethat represents a parameterized type. For example, to represent typeList<Set<Integer>>, you could callTypeFactory.parametricType(List.class, Integer.class);
NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
- Since:
- 1.5
-
constructParametricType
Factory method for constructingJavaTypethat represents a parameterized type. For example, to represent typeList<Set<Integer>>, you could callJavaType 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.
- Since:
- 1.5
-
constructRawCollectionType
Method that can be used to construct "raw" Collection type; meaning that its parameterization is unknown. This is similar to usingObject.classparameterization, and is equivalent to calling:typeFactory.constructCollectionType(collectionClass, typeFactory.unknownType());
This method should only be used if parameterization is completely unavailable.
- Since:
- 1.9
-
constructRawCollectionLikeType
Method that can be used to construct "raw" Collection-like type; meaning that its parameterization is unknown. This is similar to usingObject.classparameterization, and is equivalent to calling:typeFactory.constructCollectionLikeType(collectionClass, typeFactory.unknownType());
This method should only be used if parameterization is completely unavailable.
- Since:
- 1.9
-
constructRawMapType
Method that can be used to construct "raw" Map type; meaning that its parameterization is unknown. This is similar to usingObject.classparameterization, and is equivalent to calling:typeFactory.constructMapType(collectionClass, typeFactory.unknownType(), typeFactory.unknownType());
This method should only be used if parameterization is completely unavailable.
- Since:
- 1.9
-
constructRawMapLikeType
Method that can be used to construct "raw" Map-like type; meaning that its parameterization is unknown. This is similar to usingObject.classparameterization, and is equivalent to calling:typeFactory.constructMapLikeType(collectionClass, typeFactory.unknownType(), typeFactory.unknownType());
This method should only be used if parameterization is completely unavailable.
- Since:
- 1.9
-
_fromClass
- Parameters:
context- Mapping of formal parameter declarations (for generic types) into actual types
-
_fromParameterizedClass
Method used byTypeParserwhen generics-aware version is constructed. -
_fromParamType
This method deals with parameterized types, that is, first class generic classes.Since version 1.2, this resolves all parameterized types, not just Maps or Collections.
-
_fromArrayType
-
_fromVariable
-
_fromWildcard
-
_resolveVariableViaSubTypes
protected JavaType _resolveVariableViaSubTypes(HierarchicType leafType, String variableName, TypeBindings bindings) -
_unknownType
-
_findSuperTypeChain
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
-
_findSuperInterfaceChain
-
_doFindSuperInterfaceChain
-
_hashMapSuperInterfaceChain
-
_arrayListSuperInterfaceChain
-