Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.type

public Class TypeFactory

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@SuppressWarnings:rawtypes
Imports
java.lang.reflect.Array, .GenericArrayType, .ParameterizedType, .Type, .TypeVariable, .WildcardType, java.util.*, java.util.concurrent.atomic.AtomicReference, java.util.stream.BaseStream, .DoubleStream, .IntStream, .LongStream, .Stream, com.fasterxml.jackson.core.type.TypeReference, com.fasterxml.jackson.databind.JavaType, .JsonNode, com.fasterxml.jackson.databind.util.ArrayBuilders, .ClassUtil, .LRUMap, .LookupCache

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

Instances of this class are accessible using com.fasterxml.jackson.databind.ObjectMapper as well as many objects it constructs (like com.fasterxml.jackson.databind.DeserializationConfig and com.fasterxml.jackson.databind.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);

Note on optimizations: generic type parameters are resolved for all types, with following exceptions:

Field Summary

Modifier and TypeField and Description
protected final ClassLoader
_classLoader

ClassLoader used by this factory [databind#624].

protected final TypeModifier[]
_modifiers

Registered TypeModifiers: objects that can change details of JavaType instances factory constructs.

protected final TypeParser
protected final LookupCache<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

private static final Class<?>
private static final Class<?>
private static final Class<?>
private static final Class<?>
private static final Class<?>
private static final Class<?>
private static final Class<?>
private static final Class<?>
private static final Class<?>
protected static final SimpleType
protected static final SimpleType
CORE_TYPE_COMPARABLE

Cache Comparable because it is both parametric (relatively costly to resolve) and mostly useless (no special handling), better handle directly

protected static final SimpleType
protected static final SimpleType
CORE_TYPE_ENUM

Cache Enum because it is parametric AND self-referential (costly to resolve) and useless in itself (no special handling).

protected static final SimpleType
protected static final SimpleType
CORE_TYPE_JSON_NODE

Cache JsonNode because it is no critical path of simple tree model reading and does not have things to override

protected static final SimpleType
protected static final SimpleType
protected static final SimpleType
public static final int
DEFAULT_MAX_CACHE_SIZE

Default size used to construct _typeCache.

protected static final TypeBindings
protected static final TypeFactory
instance

Globally shared singleton.

private static final JavaType[]
private static final long

Constructor Summary

AccessConstructor and Description
private
protected
protected

Method Summary

Modifier and TypeMethod and Description
protected JavaType
_applyModifiers(Type srcType, JavaType resolvedType)

private TypeBindings
_bindingsForSubtype(JavaType baseType, int typeParamCount, Class<?> subclass, boolean relaxedCompatibilityCheck)

private JavaType
_collectionType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)

protected JavaType
_constructSimple(Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)

Factory method to call when no special JavaType is needed, no generic parameters are passed.

protected Class<?>
protected JavaType
_findWellKnownSimple(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, Type srcType, TypeBindings bindings)

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
protected JavaType
_fromClass(ClassStack context, Class<?> rawType, TypeBindings
Mapping of formal parameter declarations (for generic types) into actual types
bindings
)

protected JavaType
_fromParamType(ClassStack context, ParameterizedType ptype, TypeBindings parentBindings)

This method deals with parameterized types, that is, first class generic classes.

protected JavaType
protected JavaType
_fromWellKnownClass(ClassStack context, 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 alternate JavaType implementation.

protected JavaType
_fromWellKnownInterface(ClassStack context, Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)

protected JavaType
private JavaType
_iterationType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)

private JavaType
_iterationType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces, JavaType iteratedType)

private JavaType
_mapType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)

protected JavaType
_newSimpleType(Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)

Factory method that is to create a new SimpleType with no checks whatsoever.

private JavaType
_referenceType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)

protected JavaType
_resolveSuperClass(ClassStack context, Class<?> rawType, TypeBindings parentBindings)

protected JavaType[]
_resolveSuperInterfaces(ClassStack context, Class<?> rawType, TypeBindings parentBindings)

private String
_resolveTypePlaceholders(JavaType sourceType, JavaType actualType)

protected JavaType
private boolean
protected Class<?>
classForName(String name, boolean initialize, ClassLoader loader)

protected Class<?>
public void
clearCache()

Method that will clear up any cached type definitions that may be cached by this TypeFactory instance.

public ArrayType
constructArrayType(Class<?> elementType)

Method for constructing an ArrayType.

public ArrayType
constructArrayType(JavaType elementType)

Method for constructing an ArrayType.

public CollectionLikeType
constructCollectionLikeType(Class<?> collectionClass, Class<?> elementClass)

Method for constructing a CollectionLikeType.

public CollectionLikeType
constructCollectionLikeType(Class<?> collectionClass, JavaType elementType)

Method for constructing a CollectionLikeType.

public CollectionType
constructCollectionType(Class<? extends Collection<E>> collectionClass, Class<?> elementClass)

Method for constructing a CollectionType.

public CollectionType
constructCollectionType(Class<? extends Collection<E>> collectionClass, JavaType elementType)

Method for constructing a CollectionType.

public JavaType
constructFromCanonical(String
Canonical string representation of a type
canonical
)

Factory method for constructing a JavaType out of its canonical representation (see JavaType#toCanonical()).

public JavaType
constructGeneralizedType(JavaType baseType, Class<?> superClass)

Method similar to constructSpecializedType, but that creates a less-specific type of given type.

public MapLikeType
constructMapLikeType(Class<?> mapClass, Class<?> keyClass, Class<?> valueClass)

Method for constructing a MapLikeType instance.

public MapLikeType
constructMapLikeType(Class<?> mapClass, JavaType keyType, JavaType valueType)

Method for constructing a MapLikeType instance

Do not use this method to create a true Map type -- use constructMapType instead.

public MapType
constructMapType(Class<? extends Map<K, V>> 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.

public MapType
constructMapType(Class<? extends Map<K, V>> mapClass, JavaType keyType, JavaType valueType)

Method for constructing a MapType instance

Note

type modifiers are NOT called on constructed type itself.

public JavaType
constructParametricType(Class<?>
Type-erased type to parameterize
parametrized
,
Class<?>...
Type parameters to apply
parameterClasses
)

Factory method for constructing JavaType that represents a parameterized type.

public JavaType

Returns:

Fully resolved type for given base type and type parameters
constructParametricType
(Class<?>
Actual type-erased type
rawType
,
JavaType...
Type parameters to apply
parameterTypes
)

Factory method for constructing JavaType that represents a parameterized type.

public JavaType
constructParametricType(Class<?>
Actual type-erased type
rawType
,
TypeBindings
Type bindings for the raw type
parameterTypes
)

Factory method for constructing JavaType that represents a parameterized type.

public JavaType
constructParametrizedType(Class<?> parametrized, Class<?> parametersFor, JavaType... parameterTypes)
Deprecated since 2.9 Use constructParametricType(Class, JavaType...) instead

public JavaType
constructParametrizedType(Class<?> parametrized, Class<?> parametersFor, Class<?>... parameterClasses)
Deprecated since 2.9 Use constructParametricType(Class, Class...) instead

public CollectionLikeType
constructRawCollectionLikeType(Class<?> collectionClass)

Method that can be used to construct "raw" Collection-like type; meaning that its parameterization is unknown.

public CollectionType
constructRawCollectionType(Class<? extends Collection<E>> collectionClass)

Method that can be used to construct "raw" Collection type; meaning that its parameterization is unknown.

public MapLikeType
constructRawMapLikeType(Class<?> mapClass)

Method that can be used to construct "raw" Map-like type; meaning that its parameterization is unknown.

public MapType
constructRawMapType(Class<? extends Map<K, V>> mapClass)

Method that can be used to construct "raw" Map type; meaning that its parameterization is unknown.

public JavaType
constructReferenceType(Class<?> rawType, JavaType referredType)

Method for constructing a ReferenceType instance with given type parameter (type MUST take one and only one type parameter)

Note

type modifiers are NOT called on constructed type itself.

public JavaType
constructSimpleType(Class<?> rawType, JavaType[] parameterTypes)

Method for constructing a type instance with specified parameterization.

public JavaType
constructSimpleType(Class<?> rawType, Class<?> parameterTarget, JavaType[] parameterTypes)
Deprecated Since 2.7

Method for constructing a type instance with specified parameterization.

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.

public JavaType

Returns:

Resolved sub-type
constructSpecializedType
(JavaType
Declared base type with resolved type parameters
baseType
,
Class<?>
Runtime subtype to use for resolving
subclass
,
boolean
Whether checking for type-assignment compatibility should be "relaxed" (true) or "strict" (false): typically serialization uses relaxed, deserialization strict checking.
relaxedCompatibilityCheck
)

Factory method for creating a subtype of given base type, as defined by specified subclass; but retaining generic type information if any.

public JavaType
public JavaType
public JavaType
constructType(Type type, TypeBindings bindings)
Deprecated Since 2.12

Method that you very likely should NOT be using -- you need to know a lot about internal details of TypeBindings and even then it will probably not do what you want.

public JavaType
constructType(Type type, Class<?> contextClass)
Deprecated Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)

public JavaType
constructType(Type type, JavaType contextType)
Deprecated Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)

public static TypeFactory
defaultInstance()

Method used to access the globally shared instance, which has no custom configuration.

public Class<?>
findClass(String className)

Low-level lookup method moved from com.fasterxml.jackson.databind.util.ClassUtil, to allow for overriding of lookup functionality in environments like OSGi.

public JavaType
findFirstTypeParameter(JavaType type, Class<?> expType)

Specialized alternative to findTypeParameters

public JavaType[]
findTypeParameters(JavaType
Sub-type (leaf type) that implements expType
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.

public JavaType[]
findTypeParameters(Class<?> clz, Class<?> expType, TypeBindings bindings)
Deprecated Since 2.7 resolve raw type first, then find type parameters

public JavaType[]
findTypeParameters(Class<?> clz, Class<?> expType)
Deprecated Since 2.7 resolve raw type first, then find type parameters

public ClassLoader
public JavaType
moreSpecificType(JavaType
Primary type to consider
type1
,
JavaType
Secondary type to consider
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.

public static Class<?>
rawClass(Type t)

Static helper method that can be called to figure out type-erased call for given JDK type.

public JavaType

Returns:

Fully resolve type
resolveMemberType
(Type
Type of a java.lang.reflect.Member to resolve
type
,
TypeBindings
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 if type is of type Class<?>.
contextBindings
)

Method to call when resolving types of java.lang.reflect.Members like Fields, Methods and Constructor parameters and there is a TypeBindings (that describes binding of type parameters within context) to pass.

public JavaType
uncheckedSimpleType(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.

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.

public TypeFactory
withCache(LRUMap<Object, JavaType> cache)
Deprecated Since 2.12

Mutant factory method that will construct new TypeFactory with identical settings except for different cache; most likely one with bigger maximum size.

public TypeFactory
withCache(LookupCache<Object, JavaType> cache)

Mutant factory method that will construct new TypeFactory with identical settings except for different cache.

public TypeFactory
withClassLoader(ClassLoader classLoader)

"Mutant factory" method which will construct a new instance with specified ClassLoader to use by findClass.

public TypeFactory
withModifier(TypeModifier mod)

"Mutant factory" method which will construct a new instance with specified TypeModifier added as the first modifier to call (in case there are multiple registered).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait