Class TypeFactory
- java.lang.Object
-
- com.fasterxml.jackson.databind.type.TypeFactory
-
- All Implemented Interfaces:
java.io.Serializable
public class TypeFactory extends java.lang.Object implements java.io.Serializable
Class used for creating concreteJavaType
instances, given various inputs.Instances of this class are accessible using
ObjectMapper
as well as many objects it constructs (likeDeserializationConfig
andSerializationConfig
)), 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);
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoader
_classLoader
ClassLoader used by this factory [databind#624].protected TypeModifier[]
_modifiers
RegisteredTypeModifier
s: objects that can change details ofJavaType
instances factory constructs.protected TypeParser
_parser
protected LookupCache<java.lang.Object,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 typesprotected static SimpleType
CORE_TYPE_BOOL
protected static SimpleType
CORE_TYPE_CLASS
CacheClass
because it is nominally parametric, but has no really useful information.protected static SimpleType
CORE_TYPE_COMPARABLE
CacheComparable
because it is both parameteric (relatively costly to resolve) and mostly useless (no special handling), better handle directlyprotected static SimpleType
CORE_TYPE_ENUM
CacheEnum
because it is parametric AND self-referential (costly to resolve) and useless in itself (no special handling).protected static SimpleType
CORE_TYPE_INT
protected static SimpleType
CORE_TYPE_JSON_NODE
CacheJsonNode
because it is no critical path of simple tree model reading and does not have things to overrideprotected static SimpleType
CORE_TYPE_LONG
protected static SimpleType
CORE_TYPE_OBJECT
protected static SimpleType
CORE_TYPE_STRING
protected static TypeBindings
EMPTY_BINDINGS
protected static TypeFactory
instance
Globally shared singleton.
-
Constructor Summary
Constructors Modifier Constructor Description protected
TypeFactory(LookupCache<java.lang.Object,JavaType> typeCache)
protected
TypeFactory(LookupCache<java.lang.Object,JavaType> typeCache, TypeParser p, TypeModifier[] mods, java.lang.ClassLoader classLoader)
protected
TypeFactory(LRUMap<java.lang.Object,JavaType> typeCache)
Deprecated.Since 2.12protected
TypeFactory(LRUMap<java.lang.Object,JavaType> typeCache, TypeParser p, TypeModifier[] mods, java.lang.ClassLoader classLoader)
Deprecated.Since 2.12
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected JavaType
_applyModifiers(java.lang.reflect.Type srcType, JavaType resolvedType)
protected JavaType
_constructSimple(java.lang.Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Factory method to call when no specialJavaType
is needed, no generic parameters are passed.protected java.lang.Class<?>
_findPrimitive(java.lang.String className)
protected JavaType
_findWellKnownSimple(java.lang.Class<?> clz)
Helper method called to see if requested, non-generic-parameterized type is one of common, "well-known" types, instances of which are pre-constructed and do not need dynamic caching.protected JavaType
_fromAny(ClassStack context, java.lang.reflect.Type srcType, TypeBindings bindings)
Factory method that can be used if type information is passed as Java typing returned fromgetGenericXxx
methods (usually for a return or argument type).protected JavaType
_fromArrayType(ClassStack context, java.lang.reflect.GenericArrayType type, TypeBindings bindings)
protected JavaType
_fromClass(ClassStack context, java.lang.Class<?> rawType, TypeBindings bindings)
protected JavaType
_fromParamType(ClassStack context, java.lang.reflect.ParameterizedType ptype, TypeBindings parentBindings)
This method deals with parameterized types, that is, first class generic classes.protected JavaType
_fromVariable(ClassStack context, java.lang.reflect.TypeVariable<?> var, TypeBindings bindings)
protected JavaType
_fromWellKnownClass(ClassStack context, java.lang.Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Helper class used to check whether exact class for which type is being constructed is one of well-known base interfaces or classes that indicates alternateJavaType
implementation.protected JavaType
_fromWellKnownInterface(ClassStack context, java.lang.Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
protected JavaType
_fromWildcard(ClassStack context, java.lang.reflect.WildcardType type, TypeBindings bindings)
protected JavaType
_newSimpleType(java.lang.Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Factory method that is to create a newSimpleType
with no checks whatsoever.protected JavaType
_resolveSuperClass(ClassStack context, java.lang.Class<?> rawType, TypeBindings parentBindings)
protected JavaType[]
_resolveSuperInterfaces(ClassStack context, java.lang.Class<?> rawType, TypeBindings parentBindings)
protected JavaType
_unknownType()
protected java.lang.Class<?>
classForName(java.lang.String name)
protected java.lang.Class<?>
classForName(java.lang.String name, boolean initialize, java.lang.ClassLoader loader)
void
clearCache()
Method that will clear up any cached type definitions that may be cached by thisTypeFactory
instance.ArrayType
constructArrayType(JavaType elementType)
Method for constructing anArrayType
.ArrayType
constructArrayType(java.lang.Class<?> elementType)
Method for constructing anArrayType
.CollectionLikeType
constructCollectionLikeType(java.lang.Class<?> collectionClass, JavaType elementType)
Method for constructing aCollectionLikeType
.CollectionLikeType
constructCollectionLikeType(java.lang.Class<?> collectionClass, java.lang.Class<?> elementClass)
Method for constructing aCollectionLikeType
.CollectionType
constructCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass, JavaType elementType)
Method for constructing aCollectionType
.CollectionType
constructCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass, java.lang.Class<?> elementClass)
Method for constructing aCollectionType
.JavaType
constructFromCanonical(java.lang.String canonical)
Factory method for constructing aJavaType
out of its canonical representation (seeResolvedType.toCanonical()
).JavaType
constructGeneralizedType(JavaType baseType, java.lang.Class<?> superClass)
Method similar toconstructSpecializedType(com.fasterxml.jackson.databind.JavaType, java.lang.Class<?>)
, but that creates a less-specific type of given type.MapLikeType
constructMapLikeType(java.lang.Class<?> mapClass, JavaType keyType, JavaType valueType)
Method for constructing aMapLikeType
instanceMapLikeType
constructMapLikeType(java.lang.Class<?> mapClass, java.lang.Class<?> keyClass, java.lang.Class<?> valueClass)
Method for constructing aMapLikeType
instanceMapType
constructMapType(java.lang.Class<? extends java.util.Map> mapClass, JavaType keyType, JavaType valueType)
Method for constructing aMapType
instanceMapType
constructMapType(java.lang.Class<? extends java.util.Map> mapClass, java.lang.Class<?> keyClass, java.lang.Class<?> valueClass)
Method for constructing aMapType
instanceJavaType
constructParametricType(java.lang.Class<?> rawType, JavaType... parameterTypes)
Factory method for constructingJavaType
that represents a parameterized type.JavaType
constructParametricType(java.lang.Class<?> rawType, TypeBindings parameterTypes)
Factory method for constructingJavaType
that represents a parameterized type.JavaType
constructParametricType(java.lang.Class<?> parametrized, java.lang.Class<?>... parameterClasses)
Factory method for constructingJavaType
that represents a parameterized type.JavaType
constructParametrizedType(java.lang.Class<?> parametrized, java.lang.Class<?> parametersFor, JavaType... parameterTypes)
Deprecated.since 2.9 UseconstructParametricType(Class,JavaType...)
insteadJavaType
constructParametrizedType(java.lang.Class<?> parametrized, java.lang.Class<?> parametersFor, java.lang.Class<?>... parameterClasses)
Deprecated.since 2.9 UseconstructParametricType(Class,Class...)
insteadCollectionLikeType
constructRawCollectionLikeType(java.lang.Class<?> collectionClass)
Method that can be used to construct "raw" Collection-like type; meaning that its parameterization is unknown.CollectionType
constructRawCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass)
Method that can be used to construct "raw" Collection type; meaning that its parameterization is unknown.MapLikeType
constructRawMapLikeType(java.lang.Class<?> mapClass)
Method that can be used to construct "raw" Map-like type; meaning that its parameterization is unknown.MapType
constructRawMapType(java.lang.Class<? extends java.util.Map> mapClass)
Method that can be used to construct "raw" Map type; meaning that its parameterization is unknown.JavaType
constructReferenceType(java.lang.Class<?> rawType, JavaType referredType)
Method for constructing aReferenceType
instance with given type parameter (type MUST take one and only one type parameter)JavaType
constructSimpleType(java.lang.Class<?> rawType, JavaType[] parameterTypes)
Method for constructing a type instance with specified parameterization.JavaType
constructSimpleType(java.lang.Class<?> rawType, java.lang.Class<?> parameterTarget, JavaType[] parameterTypes)
Deprecated.Since 2.7JavaType
constructSpecializedType(JavaType baseType, java.lang.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
constructSpecializedType(JavaType baseType, java.lang.Class<?> subclass, boolean relaxedCompatibilityCheck)
Factory method for creating a subtype of given base type, as defined by specified subclass; but retaining generic type information if any.JavaType
constructType(com.fasterxml.jackson.core.type.TypeReference<?> typeRef)
JavaType
constructType(java.lang.reflect.Type type)
JavaType
constructType(java.lang.reflect.Type type, JavaType contextType)
Deprecated.Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)JavaType
constructType(java.lang.reflect.Type type, TypeBindings bindings)
Deprecated.Since 2.12JavaType
constructType(java.lang.reflect.Type type, java.lang.Class<?> contextClass)
Deprecated.Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)static TypeFactory
defaultInstance()
Method used to access the globally shared instance, which has no custom configuration.java.lang.Class<?>
findClass(java.lang.String className)
Low-level lookup method moved fromClassUtil
, to allow for overriding of lookup functionality in environments like OSGi.JavaType[]
findTypeParameters(JavaType type, java.lang.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.JavaType[]
findTypeParameters(java.lang.Class<?> clz, java.lang.Class<?> expType)
Deprecated.Since 2.7 resolve raw type first, then find type parametersJavaType[]
findTypeParameters(java.lang.Class<?> clz, java.lang.Class<?> expType, TypeBindings bindings)
Deprecated.Since 2.7 resolve raw type first, then find type parametersjava.lang.ClassLoader
getClassLoader()
JavaType
moreSpecificType(JavaType type1, JavaType type2)
Method that can be called to figure out more specific of two types (if they are related; that is, one implements or extends the other); or if not related, return the primary type.static java.lang.Class<?>
rawClass(java.lang.reflect.Type t)
Static helper method that can be called to figure out type-erased call for given JDK type.JavaType
resolveMemberType(java.lang.reflect.Type type, TypeBindings contextBindings)
Method to call when resolving types ofMember
s like Fields, Methods and Constructor parameters and there is aTypeBindings
(that describes binding of type parameters within context) to pass.JavaType
uncheckedSimpleType(java.lang.Class<?> cls)
Deprecated.Since 2.8, to indicate users should never call this method.static JavaType
unknownType()
Method for constructing a marker type that indicates missing generic type information, which is handled same as simple type forjava.lang.Object
.TypeFactory
withCache(LookupCache<java.lang.Object,JavaType> cache)
Mutant factory method that will construct newTypeFactory
with identical settings except for different cache; most likely one with bigger maximum size.TypeFactory
withCache(LRUMap<java.lang.Object,JavaType> cache)
Deprecated.Since 2.12TypeFactory
withClassLoader(java.lang.ClassLoader classLoader)
"Mutant factory" method which will construct a new instance with specifiedClassLoader
to use byfindClass(java.lang.String)
.TypeFactory
withModifier(TypeModifier mod)
"Mutant factory" method which will construct a new instance with specifiedTypeModifier
added as the first modifier to call (in case there are multiple registered).
-
-
-
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 usesdefaultInstance()
for accessing it.
-
EMPTY_BINDINGS
protected static final TypeBindings EMPTY_BINDINGS
-
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
-
CORE_TYPE_STRING
protected static final SimpleType CORE_TYPE_STRING
-
CORE_TYPE_OBJECT
protected static final SimpleType CORE_TYPE_OBJECT
-
CORE_TYPE_COMPARABLE
protected static final SimpleType CORE_TYPE_COMPARABLE
CacheComparable
because it is both parameteric (relatively costly to resolve) and mostly useless (no special handling), better handle directly- Since:
- 2.7
-
CORE_TYPE_ENUM
protected static final SimpleType CORE_TYPE_ENUM
CacheEnum
because it is parametric AND self-referential (costly to resolve) and useless in itself (no special handling).- Since:
- 2.7
-
CORE_TYPE_CLASS
protected static final SimpleType CORE_TYPE_CLASS
CacheClass
because it is nominally parametric, but has no really useful information.- Since:
- 2.7
-
CORE_TYPE_JSON_NODE
protected static final SimpleType CORE_TYPE_JSON_NODE
CacheJsonNode
because it is no critical path of simple tree model reading and does not have things to override- Since:
- 2.10
-
_typeCache
protected final LookupCache<java.lang.Object,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
-
_modifiers
protected final TypeModifier[] _modifiers
RegisteredTypeModifier
s: objects that can change details ofJavaType
instances factory constructs.
-
_parser
protected final TypeParser _parser
-
_classLoader
protected final java.lang.ClassLoader _classLoader
ClassLoader used by this factory [databind#624].
-
-
Constructor Detail
-
TypeFactory
@Deprecated protected TypeFactory(LRUMap<java.lang.Object,JavaType> typeCache)
Deprecated.Since 2.12- Since:
- 2.8
-
TypeFactory
protected TypeFactory(LookupCache<java.lang.Object,JavaType> typeCache)
- Since:
- 2.12
-
TypeFactory
@Deprecated protected TypeFactory(LRUMap<java.lang.Object,JavaType> typeCache, TypeParser p, TypeModifier[] mods, java.lang.ClassLoader classLoader)
Deprecated.Since 2.12
-
TypeFactory
protected TypeFactory(LookupCache<java.lang.Object,JavaType> typeCache, TypeParser p, TypeModifier[] mods, java.lang.ClassLoader classLoader)
- Since:
- 2.12
-
-
Method Detail
-
withModifier
public TypeFactory withModifier(TypeModifier mod)
"Mutant factory" method which will construct a new instance with specifiedTypeModifier
added as the first modifier to call (in case there are multiple registered).
-
withClassLoader
public TypeFactory withClassLoader(java.lang.ClassLoader classLoader)
"Mutant factory" method which will construct a new instance with specifiedClassLoader
to use byfindClass(java.lang.String)
.
-
withCache
@Deprecated public TypeFactory withCache(LRUMap<java.lang.Object,JavaType> cache)
Deprecated.Since 2.12Mutant factory method that will construct newTypeFactory
with identical settings except for different cache; most likely one with bigger maximum size.- Since:
- 2.8
-
withCache
public TypeFactory withCache(LookupCache<java.lang.Object,JavaType> cache)
Mutant factory method that will construct newTypeFactory
with identical settings except for different cache; most likely one with bigger maximum size.- Since:
- 2.12
-
defaultInstance
public static TypeFactory defaultInstance()
Method used to access the globally shared instance, which has no custom configuration. Used byObjectMapper
to get the default factory when constructed.
-
clearCache
public void clearCache()
Method that will clear up any cached type definitions that may be cached by thisTypeFactory
instance. This method should not be commonly used, that is, only use it if you know there is a problem with retention of type definitions; the most likely (and currently only known) problem is retention ofClass
instances viaJavaType
reference.- Since:
- 2.4.1
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
-
unknownType
public static JavaType unknownType()
Method for constructing a marker type that indicates missing generic type information, which is handled same as simple type forjava.lang.Object
.
-
rawClass
public static java.lang.Class<?> rawClass(java.lang.reflect.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.
-
findClass
public java.lang.Class<?> findClass(java.lang.String className) throws java.lang.ClassNotFoundException
Low-level lookup method moved fromClassUtil
, to allow for overriding of lookup functionality in environments like OSGi.- Throws:
java.lang.ClassNotFoundException
- Since:
- 2.6
-
classForName
protected java.lang.Class<?> classForName(java.lang.String name, boolean initialize, java.lang.ClassLoader loader) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
classForName
protected java.lang.Class<?> classForName(java.lang.String name) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
_findPrimitive
protected java.lang.Class<?> _findPrimitive(java.lang.String className)
-
constructSpecializedType
public JavaType constructSpecializedType(JavaType baseType, java.lang.Class<?> subclass) throws java.lang.IllegalArgumentException
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 givingHashMap.class
as subclass. Short-cut for:constructSpecializedType(baseType, subclass, class);
that is, will use "strict" compatibility checking, usually used for deserialization purposes (but often not for serialization).- Throws:
java.lang.IllegalArgumentException
-
constructSpecializedType
public JavaType constructSpecializedType(JavaType baseType, java.lang.Class<?> subclass, boolean relaxedCompatibilityCheck) throws java.lang.IllegalArgumentException
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 givingHashMap.class
as subclass.- Parameters:
baseType
- Declared base type with resolved type parameterssubclass
- Runtime subtype to use for resolvingrelaxedCompatibilityCheck
- Whether checking for type-assignment compatibility should be "relaxed" (true
) or "strict" (false
): typically serialization uses relaxed, deserialization strict checking.- Returns:
- Resolved sub-type
- Throws:
java.lang.IllegalArgumentException
- Since:
- 2.11
-
constructGeneralizedType
public JavaType constructGeneralizedType(JavaType baseType, java.lang.Class<?> superClass)
Method similar toconstructSpecializedType(com.fasterxml.jackson.databind.JavaType, java.lang.Class<?>)
, but that creates a less-specific type of given type. Usually this is as simple as simply finding super-type with type erasure ofsuperClass
, but there may be need for some additional work-arounds.- Parameters:
superClass
-- Since:
- 2.7
-
constructFromCanonical
public JavaType constructFromCanonical(java.lang.String canonical) throws java.lang.IllegalArgumentException
Factory method for constructing aJavaType
out of its canonical representation (seeResolvedType.toCanonical()
).- Parameters:
canonical
- Canonical string representation of a type- Throws:
java.lang.IllegalArgumentException
- If canonical representation is malformed, or class that type represents (including its generic parameters) is not found
-
findTypeParameters
public JavaType[] findTypeParameters(JavaType type, java.lang.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 implementsexpType
-
findTypeParameters
@Deprecated public JavaType[] findTypeParameters(java.lang.Class<?> clz, java.lang.Class<?> expType, TypeBindings bindings)
Deprecated.Since 2.7 resolve raw type first, then find type parameters
-
findTypeParameters
@Deprecated public JavaType[] findTypeParameters(java.lang.Class<?> clz, java.lang.Class<?> expType)
Deprecated.Since 2.7 resolve raw type first, then find type parameters
-
moreSpecificType
public JavaType moreSpecificType(JavaType type1, JavaType type2)
Method that can be called to figure out more specific of two types (if they are related; that is, one implements or extends the other); or if not related, return the primary type.- Parameters:
type1
- Primary type to considertype2
- Secondary type to consider- Since:
- 2.2
-
constructType
public JavaType constructType(java.lang.reflect.Type type)
-
constructType
public JavaType constructType(com.fasterxml.jackson.core.type.TypeReference<?> typeRef)
-
resolveMemberType
public JavaType resolveMemberType(java.lang.reflect.Type type, TypeBindings contextBindings)
Method to call when resolving types ofMember
s like Fields, Methods and Constructor parameters and there is aTypeBindings
(that describes binding of type parameters within context) to pass. This is typically used only by code in databind itself.- Parameters:
type
- Type of aMember
to resolvecontextBindings
- Type bindings from the context, often class in which member declared but may be subtype of that type (to bind actual bound type parametrers). Not used iftype
is of typeClass<?>
.- Returns:
- Fully resolve type
- Since:
- 2.12 as replacement for deprecated
constructType(Type, TypeBindings)
-
constructType
@Deprecated public JavaType constructType(java.lang.reflect.Type type, TypeBindings bindings)
Deprecated.Since 2.12Method that you very likely should NOT be using -- you need to know a lot about internal details ofTypeBindings
and even then it will probably not do what you want. Usually you would instead want to call one ofconstructXxxType()
methods (whereXxx
would be "Array", "Collection[Like]", "Map[Like]" or "Parametric").
-
constructType
@Deprecated public JavaType constructType(java.lang.reflect.Type type, java.lang.Class<?> contextClass)
Deprecated.Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)
-
constructType
@Deprecated public JavaType constructType(java.lang.reflect.Type type, JavaType contextType)
Deprecated.Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)
-
constructArrayType
public ArrayType constructArrayType(java.lang.Class<?> elementType)
Method for constructing anArrayType
.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 anArrayType
.NOTE: type modifiers are NOT called on array type itself; but are called for contained types.
-
constructCollectionType
public CollectionType constructCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass, java.lang.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(java.lang.Class<? extends java.util.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(java.lang.Class<?> collectionClass, java.lang.Class<?> elementClass)
Method for constructing aCollectionLikeType
.NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
-
constructCollectionLikeType
public CollectionLikeType constructCollectionLikeType(java.lang.Class<?> collectionClass, JavaType elementType)
Method for constructing aCollectionLikeType
.NOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
-
constructMapType
public MapType constructMapType(java.lang.Class<? extends java.util.Map> mapClass, java.lang.Class<?> keyClass, java.lang.Class<?> valueClass)
Method for constructing aMapType
instanceNOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
-
constructMapType
public MapType constructMapType(java.lang.Class<? extends java.util.Map> mapClass, JavaType keyType, JavaType valueType)
Method for constructing aMapType
instanceNOTE: type modifiers are NOT called on constructed type itself.
-
constructMapLikeType
public MapLikeType constructMapLikeType(java.lang.Class<?> mapClass, java.lang.Class<?> keyClass, java.lang.Class<?> valueClass)
Method for constructing aMapLikeType
instanceNOTE: type modifiers are NOT called on constructed type itself; but are called for contained types.
-
constructMapLikeType
public MapLikeType constructMapLikeType(java.lang.Class<?> mapClass, JavaType keyType, JavaType valueType)
Method for constructing aMapLikeType
instanceNOTE: type modifiers are NOT called on constructed type itself.
-
constructSimpleType
public JavaType constructSimpleType(java.lang.Class<?> rawType, JavaType[] parameterTypes)
Method for constructing a type instance with specified parameterization.NOTE: type modifiers are NOT called on constructed type itself.
-
constructSimpleType
@Deprecated public JavaType constructSimpleType(java.lang.Class<?> rawType, java.lang.Class<?> parameterTarget, JavaType[] parameterTypes)
Deprecated.Since 2.7Method for constructing a type instance with specified parameterization.- Since:
- 2.6
-
constructReferenceType
public JavaType constructReferenceType(java.lang.Class<?> rawType, JavaType referredType)
Method for constructing aReferenceType
instance with given type parameter (type MUST take one and only one type parameter)NOTE: type modifiers are NOT called on constructed type itself.
- Since:
- 2.6
-
uncheckedSimpleType
@Deprecated public JavaType uncheckedSimpleType(java.lang.Class<?> cls)
Deprecated.Since 2.8, to indicate users should never call this method.Method that use by core Databind functionality, and that should NOT be called by application code outside databind package.Unchecked here not only means that no checks are made as to whether given class might be non-simple type (like
CollectionType
) but also that most of supertype information is not gathered. This means that unless called on primitive types orString
, results are probably not what you want to use.
-
constructParametricType
public JavaType constructParametricType(java.lang.Class<?> parametrized, java.lang.Class<?>... parameterClasses)
Factory method for constructingJavaType
that represents a parameterized type. For example, to represent typeList<Set<Integer>>
, you could callJavaType inner = TypeFactory.constructParametricType(Set.class, Integer.class); return TypeFactory.constructParametricType(List.class, inner);
NOTE: since 2.11.2
TypeModifier
s ARE called on result (fix for [databind#2796])- Parameters:
parametrized
- Type-erased type to parameterizeparameterClasses
- Type parameters to apply- Since:
- 2.5 NOTE: was briefly deprecated for 2.6
-
constructParametricType
public JavaType constructParametricType(java.lang.Class<?> rawType, JavaType... parameterTypes)
Factory method for constructingJavaType
that represents a parameterized type. For example, to represent typeList<Set<Integer>>
, you couldJavaType inner = TypeFactory.constructParametricType(Set.class, Integer.class); return TypeFactory.constructParametricType(List.class, inner);
NOTE: since 2.11.2
TypeModifier
s ARE called on result (fix for [databind#2796])- Parameters:
rawType
- Actual type-erased typeparameterTypes
- Type parameters to apply- Returns:
- Fully resolved type for given base type and type parameters
-
constructParametricType
public JavaType constructParametricType(java.lang.Class<?> rawType, TypeBindings parameterTypes)
Factory method for constructingJavaType
that represents a parameterized type. The type's parameters are specified as an instance ofTypeBindings
. This is useful if you already have the type's parameters such as those found onJavaType
. For example, you could callreturn TypeFactory.constructParametricType(ArrayList.class, javaType.getBindings());
This effectively applies the parameterized types from oneJavaType
to another class.- Parameters:
rawType
- Actual type-erased typeparameterTypes
- Type bindings for the raw type- Since:
- 2.12
-
constructParametrizedType
@Deprecated public JavaType constructParametrizedType(java.lang.Class<?> parametrized, java.lang.Class<?> parametersFor, JavaType... parameterTypes)
Deprecated.since 2.9 UseconstructParametricType(Class,JavaType...)
instead- Since:
- 2.5 -- but will probably deprecated in 2.7 or 2.8 (not needed with 2.7)
-
constructParametrizedType
@Deprecated public JavaType constructParametrizedType(java.lang.Class<?> parametrized, java.lang.Class<?> parametersFor, java.lang.Class<?>... parameterClasses)
Deprecated.since 2.9 UseconstructParametricType(Class,Class...)
instead- Since:
- 2.5 -- but will probably deprecated in 2.7 or 2.8 (not needed with 2.7)
-
constructRawCollectionType
public CollectionType constructRawCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass)
Method that can be used to construct "raw" Collection type; meaning that its parameterization is unknown. This is similar to usingObject.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(java.lang.Class<?> collectionClass)
Method that can be used to construct "raw" Collection-like type; meaning that its parameterization is unknown. This is similar to usingObject.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(java.lang.Class<? extends java.util.Map> mapClass)
Method that can be used to construct "raw" Map type; meaning that its parameterization is unknown. This is similar to usingObject.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(java.lang.Class<?> mapClass)
Method that can be used to construct "raw" Map-like type; meaning that its parameterization is unknown. This is similar to usingObject.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.
-
_constructSimple
protected JavaType _constructSimple(java.lang.Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Factory method to call when no specialJavaType
is needed, no generic parameters are passed. Default implementation may check pre-constructed values for "well-known" types, but if none found will simply call_newSimpleType(java.lang.Class<?>, com.fasterxml.jackson.databind.type.TypeBindings, com.fasterxml.jackson.databind.JavaType, com.fasterxml.jackson.databind.JavaType[])
- Since:
- 2.7
-
_newSimpleType
protected JavaType _newSimpleType(java.lang.Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Factory method that is to create a newSimpleType
with no checks whatsoever. Default implementation calls the single argument constructor ofSimpleType
.- Since:
- 2.7
-
_unknownType
protected JavaType _unknownType()
-
_findWellKnownSimple
protected JavaType _findWellKnownSimple(java.lang.Class<?> clz)
Helper method called to see if requested, non-generic-parameterized type is one of common, "well-known" types, instances of which are pre-constructed and do not need dynamic caching.- Since:
- 2.7
-
_fromAny
protected JavaType _fromAny(ClassStack context, java.lang.reflect.Type srcType, TypeBindings bindings)
Factory method that can be used if type information is passed as Java typing returned fromgetGenericXxx
methods (usually for a return or argument type).
-
_applyModifiers
protected JavaType _applyModifiers(java.lang.reflect.Type srcType, JavaType resolvedType)
-
_fromClass
protected JavaType _fromClass(ClassStack context, java.lang.Class<?> rawType, TypeBindings bindings)
- Parameters:
bindings
- Mapping of formal parameter declarations (for generic types) into actual types
-
_resolveSuperClass
protected JavaType _resolveSuperClass(ClassStack context, java.lang.Class<?> rawType, TypeBindings parentBindings)
-
_resolveSuperInterfaces
protected JavaType[] _resolveSuperInterfaces(ClassStack context, java.lang.Class<?> rawType, TypeBindings parentBindings)
-
_fromWellKnownClass
protected JavaType _fromWellKnownClass(ClassStack context, java.lang.Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Helper class used to check whether exact class for which type is being constructed is one of well-known base interfaces or classes that indicates alternateJavaType
implementation.
-
_fromWellKnownInterface
protected JavaType _fromWellKnownInterface(ClassStack context, java.lang.Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
-
_fromParamType
protected JavaType _fromParamType(ClassStack context, java.lang.reflect.ParameterizedType ptype, TypeBindings parentBindings)
This method deals with parameterized types, that is, first class generic classes.
-
_fromArrayType
protected JavaType _fromArrayType(ClassStack context, java.lang.reflect.GenericArrayType type, TypeBindings bindings)
-
_fromVariable
protected JavaType _fromVariable(ClassStack context, java.lang.reflect.TypeVariable<?> var, TypeBindings bindings)
-
_fromWildcard
protected JavaType _fromWildcard(ClassStack context, java.lang.reflect.WildcardType type, TypeBindings bindings)
-
-