JavaType instances,
given various inputs.
Instances of this class are accessible using com.
as well as many objects it constructs (like
com. and
com.)),
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:
java.lang.Enum : Self-referential type reference is simply dropped and
Class is exposed as a simple, non-parameterized SimpleType
java.lang.Comparable : Type parameter is simply dropped and and
interface is exposed as a simple, non-parameterized SimpleType
java.lang.Class type parameter was dropped; resolution
was added back in Jackson 2.14.
java.util.Collection subtypes, resolved type is ALWAYS the parameter for
{link java.util.Collection} and not that of actually resolved subtype.
This is usually (but not always) same parameter.
java.util.Map subtypes, resolved type is ALWAYS the parameter for
{link java.util.Map} and not that of actually resolved subtype.
These are usually (but not always) same parameters.
| Modifier and Type | Field and Description |
|---|---|
| protected final ClassLoader | _classLoader
ClassLoader used by this factory [databind#624]. |
| protected final TypeModifier[] | _modifiers
Registered |
| protected final TypeParser | |
| protected final LookupCache | _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 |
| protected static final SimpleType | |
| protected static final SimpleType | CORE_TYPE_ENUM
Cache |
| protected static final SimpleType | |
| protected static final SimpleType | CORE_TYPE_JSON_NODE
Cache |
| 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 |
| protected static final TypeBindings | |
| protected static final TypeFactory | instance
Globally shared singleton. |
| private static final JavaType[] | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private | |
| protected | |
| protected | TypeFactory(LookupCache<Object, JavaType> typeCache, TypeParser p, TypeModifier[] mods, ClassLoader classLoader)
|
| Modifier and Type | Method and Description |
|---|---|
| protected JavaType | |
| 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 |
| 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 |
| 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
|
| 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 | |
| protected JavaType | _newSimpleType(Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Factory method that is to create a new |
| private JavaType | _referenceType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
|
| protected JavaType | |
| protected JavaType[] | |
| private String | |
| protected JavaType | |
| private boolean | |
| protected Class | |
| protected Class | |
| public void | clearCache()
Method that will clear up any cached type definitions that may
be cached by this |
| public ArrayType | |
| public ArrayType | |
| public CollectionLikeType | constructCollectionLikeType(Class<?> collectionClass, Class<?> elementClass)
Method for constructing a |
| public CollectionLikeType | constructCollectionLikeType(Class<?> collectionClass, JavaType elementType)
Method for constructing a |
| public CollectionType | constructCollectionType(Class<? extends Collection<E>> collectionClass, Class<?> elementClass)
Method for constructing a |
| public CollectionType | constructCollectionType(Class<? extends Collection<E>> collectionClass, JavaType elementType)
Method for constructing a |
| public JavaType | constructFromCanonical(String
Canonical string representation of a type canonical)Factory method for constructing a |
| public JavaType | constructGeneralizedType(JavaType baseType, Class<?> superClass)
Method similar to |
| public MapLikeType | constructMapLikeType(Class<?> mapClass, Class<?> keyClass, Class<?> valueClass)
Method for constructing a |
| public MapLikeType | constructMapLikeType(Class<?> mapClass, JavaType keyType, JavaType valueType)
Method for constructing a
Do not use this method to create a true Map type -- use |
| public MapType | |
| public MapType | |
| public JavaType | constructParametricType(Class<?>
Type-erased type to parameterize parametrized, Class<?>... Type parameters to apply parameterClasses)Factory method for constructing |
| public JavaType | Returns: Fully resolved type for given base type and type parametersActual type-erased type rawType, JavaType... Type parameters to apply parameterTypes)Factory method for constructing |
| public JavaType | constructParametricType(Class<?>
Actual type-erased type rawType, TypeBindings Type bindings for the raw type parameterTypes)Factory method for constructing |
| 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 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-typeDeclared 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" ( relaxedCompatibilityCheck)true) or "strict" (false): typically
serialization uses relaxed, deserialization strict checking.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 |
| 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 |
| public JavaType | findFirstTypeParameter(JavaType type, Class<?> expType)
Specialized alternative to |
| public JavaType[] | findTypeParameters(JavaType
Sub-type (leaf type) that implements type, Class<?> expType)expTypeMethod 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 | |
| public JavaType | Returns: Fully resolve typeType of a type, TypeBindings java. to resolveType 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 contextBindings)type is of type Class<?>.Method to call when resolving types of |
| 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
|
| public TypeFactory | withCache(LRUMap<Object, JavaType> cache)
Deprecated
Since 2.12
Mutant factory method that will construct new |
| public TypeFactory | withCache(LookupCache<Object, JavaType> cache)
Mutant factory method that will construct new |
| public TypeFactory | withClassLoader(ClassLoader classLoader)
"Mutant factory" method which will construct a new instance with specified
|
| public TypeFactory | withModifier(TypeModifier mod)
"Mutant factory" method which will construct a new instance with specified
|