Class JavaType
- java.lang.Object
-
- com.fasterxml.jackson.core.type.ResolvedType
-
- com.fasterxml.jackson.databind.JavaType
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.reflect.Type
- Direct Known Subclasses:
TypeBase
public abstract class JavaType extends ResolvedType implements java.io.Serializable, java.lang.reflect.Type
Base class for type token classes used both to contain information and as keys for deserializers.Instances can (only) be constructed by
com.fasterxml.jackson.databind.type.TypeFactory.Since 2.2 this implements
Typeto allow it to be pushed through interfaces that only expose that type.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract JavaTypecontainedType(int index)Method for accessing definitions of contained ("child") types.abstract intcontainedTypeCount()Method for checking how many contained types this type has.abstract java.lang.StringcontainedTypeName(int index)Deprecated.JavaTypecontainedTypeOrUnknown(int index)Convenience method that is functionally same as:JavaType t = containedType(index); if (t == null) { t = TypeFactory.unknownType(); }and typically used to eliminate need for null checks for common case where we just want to check if containedType is available first; and if not, use "unknown type" (which translates tojava.lang.Objectbasically).abstract booleanequals(java.lang.Object o)abstract JavaTypefindSuperType(java.lang.Class<?> erasedTarget)Method that may be called to find representation of given type within type hierarchy of this type: either this type (if this type has given erased type), one of its supertypes that has the erased types, or null if target is neither this type or any of its supertypes.abstract JavaType[]findTypeParameters(java.lang.Class<?> expType)Method that may be used to find paramaterization this type has for given type-erased generic target type.JavaTypeforcedNarrowBy(java.lang.Class<?> subclass)Deprecated.abstract TypeBindingsgetBindings()JavaTypegetContentType()Method for accessing content type of this type, if type has such a thing: simple types do not, structured types do (like arrays, Collections and Maps)java.lang.ObjectgetContentTypeHandler()Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind.java.lang.ObjectgetContentValueHandler()Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind.java.lang.StringgetErasedSignature()Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.abstract java.lang.StringBuildergetErasedSignature(java.lang.StringBuilder sb)Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.java.lang.StringgetGenericSignature()Method for accessing signature that contains generic type information, in form compatible with JVM 1.5 as per JLS.abstract java.lang.StringBuildergetGenericSignature(java.lang.StringBuilder sb)abstract java.util.List<JavaType>getInterfaces()Accessor for finding fully resolved interfaces this type implements, if any; empty array if none.JavaTypegetKeyType()Method for accessing key type for this type, assuming type has such a concept (only Map types do)java.lang.Class<?>getParameterSource()Deprecated.java.lang.Class<?>getRawClass()JavaTypegetReferencedType()Method for accessing type of value that instances of this type references, if any.abstract JavaTypegetSuperClass()Accessor for finding fully resolved parent class of this type, if it has one; null if not.<T> TgetTypeHandler()Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind.<T> TgetValueHandler()Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind.booleanhasContentType()Accessor that allows determining whethergetContentType()should return a non-null value (that is, there is a "content type") or not.booleanhasGenericTypes()Method that can be used to find out if the type directly declares generic parameters (for its direct super-class and/or super-interfaces).booleanhasHandlers()Helper method that checks whether this type, or its (optional) key or content type hasgetValueHandler()orgetTypeHandler(); that is, are there any non-standard handlers associated with this type object.inthashCode()booleanhasRawClass(java.lang.Class<?> clz)Method that can be used to check whether this type has specified Class as its type erasure.booleanhasValueHandler()booleanisAbstract()booleanisArrayType()booleanisCollectionLikeType()booleanisConcrete()Convenience method for checking whether underlying Java type is a concrete class or not: abstract classes and interfaces are not.abstract booleanisContainerType()booleanisEnumImplType()Similar toisEnumType()except does NOT returntrueforEnum(since that is not Enum implementation type).booleanisEnumType()Method that basically does equivalent of:booleanisFinal()booleanisInterface()booleanisJavaLangObject()Convenience method, short-hand forgetRawClass() == Object.classand used to figure if we basically have "untyped" type object.booleanisMapLikeType()booleanisPrimitive()booleanisRecordType()booleanisThrowable()booleanisTypeOrSubTypeOf(java.lang.Class<?> clz)booleanisTypeOrSuperTypeOf(java.lang.Class<?> clz)abstract JavaTyperefine(java.lang.Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)Mutant factory method that will try to create and return a sub-type instance for known parameterized types; for other types will return `null` to indicate that no just refinement makes necessary sense, without trying to detect special status through implemented interfaces.abstract java.lang.StringtoString()booleanuseStaticType()Accessor for checking whether handlers for dealing with values of this type should use static typing (as opposed to dynamic typing).abstract JavaTypewithContentType(JavaType contentType)Mutant factory method that may be called on structured types that have a so-called content type (element of arrays, value type of Maps, referenced type of referential types), and will construct a new instance that is identical to this instance, except that it has specified content type, instead of current one.abstract JavaTypewithContentTypeHandler(java.lang.Object h)Internal method that should not be used by any code outside of jackson-databind: only used internally by databind.abstract JavaTypewithContentValueHandler(java.lang.Object h)Internal method that should not be used by any code outside of jackson-databind: only used internally by databind.JavaTypewithHandlersFrom(JavaType src)Internal method that should not be used by any code outside of jackson-databind: only used internally by databind.abstract JavaTypewithStaticTyping()Method that can be called to get a type instance that indicates that values of the type should be handled using "static typing" for purposes of serialization (as opposed to "dynamic" aka runtime typing): meaning that no runtime information is needed for determining serializers to use.abstract JavaTypewithTypeHandler(java.lang.Object h)Internal method that should not be used by any code outside of jackson-databind: only used internally by databind.abstract JavaTypewithValueHandler(java.lang.Object h)Internal method that should not be used by any code outside of jackson-databind: only used internally by databind.-
Methods inherited from class com.fasterxml.jackson.core.type.ResolvedType
isReferenceType, toCanonical
-
-
-
-
Method Detail
-
withContentType
public abstract JavaType withContentType(JavaType contentType)
Mutant factory method that may be called on structured types that have a so-called content type (element of arrays, value type of Maps, referenced type of referential types), and will construct a new instance that is identical to this instance, except that it has specified content type, instead of current one. If content type is already set to given type,thisis returned. If type does not have a content type (which is the case withSimpleType),IllegalArgumentExceptionwill be thrown.- Returns:
- Newly created type instance
- Since:
- 2.7
-
withStaticTyping
public abstract JavaType withStaticTyping()
Method that can be called to get a type instance that indicates that values of the type should be handled using "static typing" for purposes of serialization (as opposed to "dynamic" aka runtime typing): meaning that no runtime information is needed for determining serializers to use. The main use case is to allow forcing of specific root value serialization type, and specifically in resolving serializers for contained types (element types for arrays, Collections and Maps).- Since:
- 2.2
-
withTypeHandler
public abstract JavaType withTypeHandler(java.lang.Object h)
Internal method that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.This mutant factory method will construct a new instance that is identical to this instance, except that it will have specified type handler assigned.
- Parameters:
h- Handler to pass to new instance created- Returns:
- Newly created type instance with same type information, specified handler
-
withContentTypeHandler
public abstract JavaType withContentTypeHandler(java.lang.Object h)
Internal method that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.This mutant factory method will construct a new instance that is identical to this instance, except that it will have specified content type (element type for arrays, value type for Maps and so forth) handler assigned.
- Parameters:
h- Handler to pass to new instance created- Returns:
- Newly created type instance with same type information, specified handler
-
withValueHandler
public abstract JavaType withValueHandler(java.lang.Object h)
Internal method that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.This mutant factory method will construct a new instance that is identical to this instance, except that it will have specified value handler assigned.
- Parameters:
h- Handler to pass to new instance created- Returns:
- Newly created type instance with same type information, specified handler
-
withContentValueHandler
public abstract JavaType withContentValueHandler(java.lang.Object h)
Internal method that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.Mutant factory method that will construct a new instance that is identical to this instance, except that it will have specified content value handler assigned.
- Parameters:
h- Handler to pass to new instance created- Returns:
- Newly created type instance with same type information, specified handler
-
withHandlersFrom
public JavaType withHandlersFrom(JavaType src)
Internal method that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.Mutant factory method that will try to copy handlers that the specified source type instance had, if any; this must be done recursively where necessary (as content types may be structured).
- Since:
- 2.8.4
-
refine
public abstract JavaType refine(java.lang.Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
Mutant factory method that will try to create and return a sub-type instance for known parameterized types; for other types will return `null` to indicate that no just refinement makes necessary sense, without trying to detect special status through implemented interfaces.- Since:
- 2.7
-
forcedNarrowBy
@Deprecated public JavaType forcedNarrowBy(java.lang.Class<?> subclass)
Deprecated.Legacy method used for forcing sub-typing of this type into type specified by specific type erasure. Deprecated as of 2.7 as such specializations really ought to go throughTypeFactory, not directly viaJavaType.- Since:
- 2.7
-
getRawClass
public final java.lang.Class<?> getRawClass()
- Specified by:
getRawClassin classResolvedType- Returns:
- Type-erased
Classof resolved type
-
hasRawClass
public final boolean hasRawClass(java.lang.Class<?> clz)
Method that can be used to check whether this type has specified Class as its type erasure. Put another way, returns true if instantiation of this Type is given (type-erased) Class.- Specified by:
hasRawClassin classResolvedType
-
hasContentType
public boolean hasContentType()
Accessor that allows determining whethergetContentType()should return a non-null value (that is, there is a "content type") or not. True ifisContainerType()orResolvedType.isReferenceType()return true.- Since:
- 2.8
-
isTypeOrSubTypeOf
public final boolean isTypeOrSubTypeOf(java.lang.Class<?> clz)
- Since:
- 2.6
-
isTypeOrSuperTypeOf
public final boolean isTypeOrSuperTypeOf(java.lang.Class<?> clz)
- Since:
- 2.9
-
isAbstract
public boolean isAbstract()
- Specified by:
isAbstractin classResolvedType
-
isConcrete
public boolean isConcrete()
Convenience method for checking whether underlying Java type is a concrete class or not: abstract classes and interfaces are not.- Specified by:
isConcretein classResolvedType
-
isThrowable
public boolean isThrowable()
- Specified by:
isThrowablein classResolvedType
-
isArrayType
public boolean isArrayType()
- Specified by:
isArrayTypein classResolvedType
-
isEnumType
public final boolean isEnumType()
Method that basically does equivalent of:Enum.class.isAssignableFrom(getRawClass())
that is, returntrueif the underlying type erased class isEnumor one its subtypes (Enum implementations).- Specified by:
isEnumTypein classResolvedType
-
isEnumImplType
public final boolean isEnumImplType()
Similar toisEnumType()except does NOT returntrueforEnum(since that is not Enum implementation type).- Since:
- 2.11
-
isRecordType
public final boolean isRecordType()
- Since:
- 2.12
-
isInterface
public final boolean isInterface()
- Specified by:
isInterfacein classResolvedType
-
isPrimitive
public final boolean isPrimitive()
- Specified by:
isPrimitivein classResolvedType
-
isFinal
public final boolean isFinal()
- Specified by:
isFinalin classResolvedType
-
isContainerType
public abstract boolean isContainerType()
- Specified by:
isContainerTypein classResolvedType- Returns:
- True if type represented is a container type; this includes array, Map and Collection types.
-
isCollectionLikeType
public boolean isCollectionLikeType()
- Specified by:
isCollectionLikeTypein classResolvedType- Returns:
- True if type is either true
Collectiontype, or something similar (meaning it has at least one type parameter, which describes type of contents)
-
isMapLikeType
public boolean isMapLikeType()
- Specified by:
isMapLikeTypein classResolvedType- Returns:
- True if type is either true
Maptype, or something similar (meaning it has at least two type parameter; first one describing key type, second value type)
-
isJavaLangObject
public final boolean isJavaLangObject()
Convenience method, short-hand forgetRawClass() == Object.classand used to figure if we basically have "untyped" type object.- Since:
- 2.5
-
useStaticType
public final boolean useStaticType()
Accessor for checking whether handlers for dealing with values of this type should use static typing (as opposed to dynamic typing). Note that while value of 'true' does mean that static typing is to be used, value of 'false' may still be overridden by other settings.- Since:
- 2.2
-
hasGenericTypes
public boolean hasGenericTypes()
Description copied from class:ResolvedTypeMethod that can be used to find out if the type directly declares generic parameters (for its direct super-class and/or super-interfaces).- Specified by:
hasGenericTypesin classResolvedType- Returns:
Trueif this type has generic type parameters,falseif not
-
getKeyType
public JavaType getKeyType()
Description copied from class:ResolvedTypeMethod for accessing key type for this type, assuming type has such a concept (only Map types do)- Specified by:
getKeyTypein classResolvedType- Returns:
- Key type of this type, if any;
nullif none
-
getContentType
public JavaType getContentType()
Description copied from class:ResolvedTypeMethod for accessing content type of this type, if type has such a thing: simple types do not, structured types do (like arrays, Collections and Maps)- Specified by:
getContentTypein classResolvedType- Returns:
- Content type of this type, if any;
nullif none
-
getReferencedType
public JavaType getReferencedType()
Description copied from class:ResolvedTypeMethod for accessing type of value that instances of this type references, if any.- Specified by:
getReferencedTypein classResolvedType- Returns:
- Referenced type, if any;
nullif not.
-
containedTypeCount
public abstract int containedTypeCount()
Description copied from class:ResolvedTypeMethod for checking how many contained types this type has. Contained types are usually generic types, so that generic Maps have 2 contained types.- Specified by:
containedTypeCountin classResolvedType- Returns:
- Number of contained types that may be accessed
-
containedType
public abstract JavaType containedType(int index)
Description copied from class:ResolvedTypeMethod for accessing definitions of contained ("child") types.- Specified by:
containedTypein classResolvedType- Parameters:
index- Index of contained type to return- Returns:
- Contained type at index, or null if no such type exists (no exception thrown)
-
containedTypeName
@Deprecated public abstract java.lang.String containedTypeName(int index)
Deprecated.Description copied from class:ResolvedTypeMethod for accessing name of type variable in indicated position. If no name is bound, will use placeholders (derived from 0-based index); if no type variable or argument exists with given index, null is returned.- Specified by:
containedTypeNamein classResolvedType- Parameters:
index- Index of contained type to return- Returns:
- Contained type at index, or null if no such type exists (no exception thrown)
-
getParameterSource
@Deprecated public java.lang.Class<?> getParameterSource()
Deprecated.- Overrides:
getParameterSourcein classResolvedType- Returns:
- Type-erased class of something not usable at this point
-
containedTypeOrUnknown
public JavaType containedTypeOrUnknown(int index)
Convenience method that is functionally same as:JavaType t = containedType(index); if (t == null) { t = TypeFactory.unknownType(); }and typically used to eliminate need for null checks for common case where we just want to check if containedType is available first; and if not, use "unknown type" (which translates tojava.lang.Objectbasically).- Since:
- 2.5
-
getBindings
public abstract TypeBindings getBindings()
- Since:
- 2.7
-
findSuperType
public abstract JavaType findSuperType(java.lang.Class<?> erasedTarget)
Method that may be called to find representation of given type within type hierarchy of this type: either this type (if this type has given erased type), one of its supertypes that has the erased types, or null if target is neither this type or any of its supertypes.- Since:
- 2.7
-
getSuperClass
public abstract JavaType getSuperClass()
Accessor for finding fully resolved parent class of this type, if it has one; null if not.- Since:
- 2.7
-
getInterfaces
public abstract java.util.List<JavaType> getInterfaces()
Accessor for finding fully resolved interfaces this type implements, if any; empty array if none.- Since:
- 2.7
-
findTypeParameters
public abstract JavaType[] findTypeParameters(java.lang.Class<?> expType)
Method that may be used to find paramaterization this type has for given type-erased generic target type.- Since:
- 2.7
-
getValueHandler
public <T> T getValueHandler()
Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.- Returns:
- Value handler associated with this type, if any.
-
getTypeHandler
public <T> T getTypeHandler()
Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.- Returns:
- Type handler associated with this type, if any.
-
getContentValueHandler
public java.lang.Object getContentValueHandler()
Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.- Returns:
- Content value handler associated with this type, if any.
- Since:
- 2.7
-
getContentTypeHandler
public java.lang.Object getContentTypeHandler()
Internal accessor that should not be used by any code outside of jackson-databind: only used internally by databind. May be removed from Jackson 3.0.- Returns:
- Content type handler associated with this type, if any.
- Since:
- 2.7
-
hasValueHandler
public boolean hasValueHandler()
- Since:
- 2.6
-
hasHandlers
public boolean hasHandlers()
Helper method that checks whether this type, or its (optional) key or content type hasgetValueHandler()orgetTypeHandler(); that is, are there any non-standard handlers associated with this type object.- Since:
- 2.8
-
getGenericSignature
public java.lang.String getGenericSignature()
Method for accessing signature that contains generic type information, in form compatible with JVM 1.5 as per JLS. It is a superset ofgetErasedSignature(), in that generic information can be automatically removed if necessary (just remove outermost angle brackets along with content inside)
-
getGenericSignature
public abstract java.lang.StringBuilder getGenericSignature(java.lang.StringBuilder sb)
- Parameters:
sb- StringBuilder to append signature to- Returns:
- StringBuilder that was passed in; returned to allow call chaining
-
getErasedSignature
public java.lang.String getErasedSignature()
Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.
-
getErasedSignature
public abstract java.lang.StringBuilder getErasedSignature(java.lang.StringBuilder sb)
Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.- Parameters:
sb- StringBuilder to append signature to- Returns:
- StringBuilder that was passed in; returned to allow call chaining
-
toString
public abstract java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public abstract boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-