Package com.fasterxml.jackson.databind
Class JavaType
- java.lang.Object
-
- com.fasterxml.jackson.core.type.ResolvedType
-
- com.fasterxml.jackson.databind.JavaType
-
- All Implemented Interfaces:
Serializable,Type
- Direct Known Subclasses:
TypeBase
public abstract class JavaType extends com.fasterxml.jackson.core.type.ResolvedType implements Serializable, 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
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_asStaticWhether entities defined with this type should be handled using static typing (as opposed to dynamic runtime type) or not.protected Class<?>_classThis is the nominal type-erased Class that would be close to the type represented (but not exactly type, due to type erasure: type instance may have more information on this).protected int_hashprotected Object_typeHandlerOptional handler that can be attached to indicate how to handle additional type metadata associated with this type.protected Object_valueHandlerOptional handler (codec) that can be attached to indicate what to use for handling (serializing, deserializing) values of this specific type.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected abstract JavaType_narrow(Class<?> subclass)Deprecated.abstract JavaTypecontainedType(int index)abstract intcontainedTypeCount()abstract 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(Object o)abstract JavaTypefindSuperType(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(Class<?> expType)Method that may be used to find paramaterization this type has for given type-erased generic target type.JavaTypeforcedNarrowBy(Class<?> subclass)Deprecated.abstract TypeBindingsgetBindings()JavaTypegetContentType()ObjectgetContentTypeHandler()ObjectgetContentValueHandler()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 StringBuildergetErasedSignature(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.StringgetGenericSignature()Method for accessing signature that contains generic type information, in form compatible with JVM 1.5 as per JLS.abstract StringBuildergetGenericSignature(StringBuilder sb)abstract List<JavaType>getInterfaces()Accessor for finding fully resolved interfaces this type implements, if any; empty array if none.JavaTypegetKeyType()Class<?>getParameterSource()Deprecated.Class<?>getRawClass()JavaTypegetReferencedType()abstract JavaTypegetSuperClass()Accessor for finding fully resolved parent class of this type, if it has one; null if not.<T> TgetTypeHandler()Method for accessing type handler associated with this type, if any<T> TgetValueHandler()Method for accessing value handler associated with this type, if anybooleanhasContentType()Accessor that allows determining whethergetContentType()should return a non-null value (that is, there is a "content type") or not.booleanhasGenericTypes()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(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()booleanisEnumType()booleanisFinal()booleanisInterface()booleanisJavaLangObject()Convenience method, short-hand forgetRawClass() == Object.classand used to figure if we basically have "untyped" type object.booleanisMapLikeType()booleanisPrimitive()booleanisThrowable()booleanisTypeOrSubTypeOf(Class<?> clz)booleanisTypeOrSuperTypeOf(Class<?> clz)abstract JavaTyperefine(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 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(Object h)Mutant factory method that 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.abstract JavaTypewithContentValueHandler(Object h)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.JavaTypewithHandlersFrom(JavaType src)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).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(Object h)"Copy method" that will construct a new instance that is identical to this instance, except that it will have specified type handler assigned.abstract JavaTypewithValueHandler(Object h)Mutant factory method that will construct a new instance that is identical to this instance, except that it will have specified value handler assigned.-
Methods inherited from class com.fasterxml.jackson.core.type.ResolvedType
isReferenceType, toCanonical
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.reflect.Type
getTypeName
-
-
-
-
Field Detail
-
_class
protected final Class<?> _class
This is the nominal type-erased Class that would be close to the type represented (but not exactly type, due to type erasure: type instance may have more information on this). May be an interface or abstract class, so instantiation may not be possible.
-
_hash
protected final int _hash
-
_valueHandler
protected final Object _valueHandler
Optional handler (codec) that can be attached to indicate what to use for handling (serializing, deserializing) values of this specific type.Note: untyped (i.e. caller has to cast) because it is used for different kinds of handlers, with unrelated types.
-
_typeHandler
protected final Object _typeHandler
Optional handler that can be attached to indicate how to handle additional type metadata associated with this type.Note: untyped (i.e. caller has to cast) because it is used for different kinds of handlers, with unrelated types.
-
_asStatic
protected final boolean _asStatic
Whether entities defined with this type should be handled using static typing (as opposed to dynamic runtime type) or not.- Since:
- 2.2
-
-
Constructor Detail
-
JavaType
protected JavaType(Class<?> raw, int additionalHash, Object valueHandler, Object typeHandler, boolean asStatic)
- Parameters:
raw- "Raw" (type-erased) class for this typeadditionalHash- Additional hash code to use, in addition to hash code of the class name
-
JavaType
protected JavaType(JavaType base)
Copy-constructor used when refining/upgrading type instances.- Since:
- 2.7
-
-
Method Detail
-
withTypeHandler
public abstract JavaType withTypeHandler(Object h)
"Copy method" that will construct a new instance that is identical to this instance, except that it will have specified type handler assigned.- Returns:
- Newly created type instance
-
withContentTypeHandler
public abstract JavaType withContentTypeHandler(Object h)
Mutant factory method that 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.- Returns:
- Newly created type instance, with given
-
withValueHandler
public abstract JavaType withValueHandler(Object h)
Mutant factory method that will construct a new instance that is identical to this instance, except that it will have specified value handler assigned.- Returns:
- Newly created type instance
-
withContentValueHandler
public abstract JavaType withContentValueHandler(Object h)
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.- Returns:
- Newly created type instance
-
withHandlersFrom
public JavaType withHandlersFrom(JavaType src)
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
-
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
-
refine
public abstract JavaType refine(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(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
-
_narrow
@Deprecated protected abstract JavaType _narrow(Class<?> subclass)
Deprecated.
-
getRawClass
public final Class<?> getRawClass()
- Specified by:
getRawClassin classcom.fasterxml.jackson.core.type.ResolvedType
-
hasRawClass
public final boolean hasRawClass(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 classcom.fasterxml.jackson.core.type.ResolvedType
-
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(Class<?> clz)
- Since:
- 2.6
-
isTypeOrSuperTypeOf
public final boolean isTypeOrSuperTypeOf(Class<?> clz)
- Since:
- 2.9
-
isAbstract
public boolean isAbstract()
- Specified by:
isAbstractin classcom.fasterxml.jackson.core.type.ResolvedType
-
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 classcom.fasterxml.jackson.core.type.ResolvedType
-
isThrowable
public boolean isThrowable()
- Specified by:
isThrowablein classcom.fasterxml.jackson.core.type.ResolvedType
-
isArrayType
public boolean isArrayType()
- Specified by:
isArrayTypein classcom.fasterxml.jackson.core.type.ResolvedType
-
isEnumType
public final boolean isEnumType()
- Specified by:
isEnumTypein classcom.fasterxml.jackson.core.type.ResolvedType
-
isInterface
public final boolean isInterface()
- Specified by:
isInterfacein classcom.fasterxml.jackson.core.type.ResolvedType
-
isPrimitive
public final boolean isPrimitive()
- Specified by:
isPrimitivein classcom.fasterxml.jackson.core.type.ResolvedType
-
isFinal
public final boolean isFinal()
- Specified by:
isFinalin classcom.fasterxml.jackson.core.type.ResolvedType
-
isContainerType
public abstract boolean isContainerType()
- Specified by:
isContainerTypein classcom.fasterxml.jackson.core.type.ResolvedType- Returns:
- True if type represented is a container type; this includes array, Map and Collection types.
-
isCollectionLikeType
public boolean isCollectionLikeType()
- Specified by:
isCollectionLikeTypein classcom.fasterxml.jackson.core.type.ResolvedType- 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 classcom.fasterxml.jackson.core.type.ResolvedType- 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()
- Specified by:
hasGenericTypesin classcom.fasterxml.jackson.core.type.ResolvedType
-
getKeyType
public JavaType getKeyType()
- Specified by:
getKeyTypein classcom.fasterxml.jackson.core.type.ResolvedType
-
getContentType
public JavaType getContentType()
- Specified by:
getContentTypein classcom.fasterxml.jackson.core.type.ResolvedType
-
getReferencedType
public JavaType getReferencedType()
- Specified by:
getReferencedTypein classcom.fasterxml.jackson.core.type.ResolvedType
-
containedTypeCount
public abstract int containedTypeCount()
- Specified by:
containedTypeCountin classcom.fasterxml.jackson.core.type.ResolvedType
-
containedType
public abstract JavaType containedType(int index)
- Specified by:
containedTypein classcom.fasterxml.jackson.core.type.ResolvedType
-
containedTypeName
@Deprecated public abstract String containedTypeName(int index)
Deprecated.- Specified by:
containedTypeNamein classcom.fasterxml.jackson.core.type.ResolvedType
-
getParameterSource
@Deprecated public Class<?> getParameterSource()
Deprecated.- Overrides:
getParameterSourcein classcom.fasterxml.jackson.core.type.ResolvedType
-
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(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 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(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()
Method for accessing value handler associated with this type, if any
-
getTypeHandler
public <T> T getTypeHandler()
Method for accessing type handler associated with this type, if any
-
getContentValueHandler
public Object getContentValueHandler()
- Since:
- 2.7
-
getContentTypeHandler
public Object getContentTypeHandler()
- 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 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 StringBuilder getGenericSignature(StringBuilder sb)
- Parameters:
sb- StringBuilder to append signature to- Returns:
- StringBuilder that was passed in; returned to allow call chaining
-
getErasedSignature
public 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 StringBuilder getErasedSignature(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
-
-