com.fasterxml.jackson.databind.type

Class TypeFactory

  • All Implemented Interfaces:
    Serializable


    public class TypeFactoryextends Objectimplements Serializable
    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);

    See Also:
    Serialized Form
    • 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.
      • 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
        Cache Comparable 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
        Cache Enum 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
        Cache Class 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
        Cache JsonNode because it is no critical path of simple tree model reading and does not have things to override
        Since:
        2.10
      • _typeCache

        protected final LRUMap<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
      • _classLoader

        protected final ClassLoader _classLoader
        ClassLoader used by this factory [databind#624].
    • Method Detail

      • withModifier

        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).
      • withCache

        public TypeFactory withCache(LRUMap<Object,JavaType> cache)
        Mutant factory method that will construct new TypeFactory with identical settings except for different cache; most likely one with bigger maximum size.
        Since:
        2.8
      • 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.
      • clearCache

        public void clearCache()
        Method that will clear up any cached type definitions that may be cached by this TypeFactory 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 of Class instances via JavaType reference.
        Since:
        2.4.1
      • 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.
      • _findPrimitive

        protected Class<?> _findPrimitive(String className)
      • 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.
      • 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

        @Deprecatedpublic JavaType[] findTypeParameters(Class<?> clz,                                                 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 consider
        type2 - Secondary type to consider
        Since:
        2.2
      • constructType

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

        @Deprecatedpublic JavaType constructType(Type type,                                          JavaType contextType)
        Deprecated. Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)
      • 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,                                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.

      • 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.

      • 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.

      • 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.

      • constructSimpleType

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

        NOTE: was briefly deprecated for 2.6.

      • constructSimpleType

        @Deprecatedpublic JavaType constructSimpleType(Class<?> rawType,                                                Class<?> parameterTarget,                                                JavaType[] parameterTypes)
        Deprecated. Since 2.7
        Method for constructing a type instance with specified parameterization.
        Since:
        2.6
      • constructReferenceType

        public JavaType constructReferenceType(Class<?> rawType,                                       JavaType referredType)
        Since:
        2.6
      • uncheckedSimpleType

        @Deprecatedpublic 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.

        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 or String, results are probably not what you want to use.

      • 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
          JavaType inner = TypeFactory.constructParametricType(Set.class, Set.class, Integer.class);  return TypeFactory.constructParametricType(ArrayList.class, List.class, inner);

        The reason for first two arguments to be separate is that parameterization may apply to a super-type. For example, if generic type was instead to be constructed for ArrayList<Integer>, the usual call would be:

          TypeFactory.constructParametricType(ArrayList.class, List.class, Integer.class);
        since parameterization is applied to List. In most cases distinction does not matter, but there are types where it does; one such example is parameterization of types that implement Iterator.

        NOTE: type modifiers are NOT called on constructed type.

        Parameters:
        parametrized - Actual full type
        parameterClasses - Type parameters to apply
        Since:
        2.5 NOTE: was briefly deprecated for 2.6
      • constructParametricType

        public JavaType constructParametricType(Class<?> rawType,                                        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.constructParametricType(Set.class, Set.class, Integer.class);  return TypeFactory.constructParametricType(ArrayList.class, List.class, inner);

        The reason for first two arguments to be separate is that parameterization may apply to a super-type. For example, if generic type was instead to be constructed for ArrayList<Integer>, the usual call would be:

          TypeFactory.constructParametricType(ArrayList.class, List.class, Integer.class);
        since parameterization is applied to List. In most cases distinction does not matter, but there are types where it does; one such example is parameterization of types that implement Iterator.

        NOTE: type modifiers are NOT called on constructed type.

        Parameters:
        rawType - Actual type-erased type
        parameterTypes - Type parameters to apply
        Since:
        2.5 NOTE: was briefly deprecated for 2.6
      • 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.

      • _unknownType

        protected JavaType _unknownType()
      • _findWellKnownSimple

        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.
        Since:
        2.7
      • _fromAny

        protected JavaType _fromAny(ClassStack context,                            Type type,                            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).
      • _fromClass

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

        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.

Copyright © 2008–2020 FasterXML. All rights reserved.



NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14