public abstract class JavaType extends ResolvedType implements java.io.Serializable, java.lang.reflect.Type
Instances can (only) be constructed by
com.fasterxml.jackson.databind.type.TypeFactory
.
Since 2.2 this implements Type
to allow
it to be pushed through interfaces that only expose that type.
Modifier and Type | Method and Description |
---|---|
abstract JavaType |
containedType(int index)
Method for accessing definitions of contained ("child")
types.
|
abstract int |
containedTypeCount()
Method for checking how many contained types this type
has.
|
abstract java.lang.String |
containedTypeName(int index)
Deprecated.
|
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 to java.lang.Object
basically). |
abstract boolean |
equals(java.lang.Object o) |
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.
|
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.
|
JavaType |
forcedNarrowBy(java.lang.Class<?> subclass)
Deprecated.
|
abstract TypeBindings |
getBindings() |
JavaType |
getContentType()
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.Object |
getContentTypeHandler()
Internal accessor that should not be used by any code outside of
jackson-databind: only used internally by databind.
|
java.lang.Object |
getContentValueHandler()
Internal accessor that should not be used by any code outside of
jackson-databind: only used internally by databind.
|
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.
|
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.
|
java.lang.String |
getGenericSignature()
Method for accessing signature that contains generic
type information, in form compatible with JVM 1.5
as per JLS.
|
abstract java.lang.StringBuilder |
getGenericSignature(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.
|
JavaType |
getKeyType()
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() |
JavaType |
getReferencedType()
Method for accessing type of value that instances of this
type references, if any.
|
abstract JavaType |
getSuperClass()
Accessor for finding fully resolved parent class of this type,
if it has one; null if not.
|
<T> T |
getTypeHandler()
Internal accessor that should not be used by any code outside of
jackson-databind: only used internally by databind.
|
<T> T |
getValueHandler()
Internal accessor that should not be used by any code outside of
jackson-databind: only used internally by databind.
|
boolean |
hasContentType()
Accessor that allows determining whether
getContentType() should
return a non-null value (that is, there is a "content type") or not. |
boolean |
hasGenericTypes()
Method that can be used to find out if the type directly declares generic
parameters (for its direct super-class and/or super-interfaces).
|
boolean |
hasHandlers()
Helper method that checks whether this type, or its (optional) key
or content type has
getValueHandler() or getTypeHandler() ;
that is, are there any non-standard handlers associated with this
type object. |
int |
hashCode() |
boolean |
hasRawClass(java.lang.Class<?> clz)
Method that can be used to check whether this type has
specified Class as its type erasure.
|
boolean |
hasValueHandler() |
boolean |
isAbstract() |
boolean |
isArrayType() |
boolean |
isCollectionLikeType() |
boolean |
isConcrete()
Convenience method for checking whether underlying Java type
is a concrete class or not: abstract classes and interfaces
are not.
|
abstract boolean |
isContainerType() |
boolean |
isEnumImplType()
Similar to
isEnumType() except does NOT return true
for Enum (since that is not Enum implementation type). |
boolean |
isEnumType()
Method that basically does equivalent of:
|
boolean |
isFinal() |
boolean |
isInterface() |
boolean |
isJavaLangObject()
Convenience method, short-hand for
getRawClass() == Object.class
and used to figure if we basically have "untyped" type object. |
boolean |
isMapLikeType() |
boolean |
isPrimitive() |
boolean |
isRecordType() |
boolean |
isThrowable() |
boolean |
isTypeOrSubTypeOf(java.lang.Class<?> clz) |
boolean |
isTypeOrSuperTypeOf(java.lang.Class<?> clz) |
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.
|
abstract java.lang.String |
toString() |
boolean |
useStaticType()
Accessor for checking whether handlers for dealing with values of
this type should use static typing (as opposed to dynamic typing).
|
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.
|
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.
|
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.
|
JavaType |
withHandlersFrom(JavaType src)
Internal method that should not be used by any code outside of
jackson-databind: only used internally by databind.
|
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.
|
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.
|
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.
|
isReferenceType, toCanonical
public abstract JavaType withContentType(JavaType contentType)
this
is returned.
If type does not have a content type (which is the case with
SimpleType
), IllegalArgumentException
will be thrown.public abstract JavaType withStaticTyping()
public abstract JavaType withTypeHandler(java.lang.Object h)
This mutant factory method will construct a new instance that is identical to this instance, except that it will have specified type handler assigned.
h
- Handler to pass to new instance createdpublic abstract JavaType withContentTypeHandler(java.lang.Object h)
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.
h
- Handler to pass to new instance createdpublic abstract JavaType withValueHandler(java.lang.Object h)
This mutant factory method will construct a new instance that is identical to this instance, except that it will have specified value handler assigned.
h
- Handler to pass to new instance createdpublic abstract JavaType withContentValueHandler(java.lang.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.
h
- Handler to pass to new instance createdpublic 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).
public abstract JavaType refine(java.lang.Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
@Deprecated public JavaType forcedNarrowBy(java.lang.Class<?> subclass)
TypeFactory
, not directly via JavaType
.public final java.lang.Class<?> getRawClass()
getRawClass
in class ResolvedType
Class
of resolved typepublic final boolean hasRawClass(java.lang.Class<?> clz)
hasRawClass
in class ResolvedType
public boolean hasContentType()
getContentType()
should
return a non-null value (that is, there is a "content type") or not.
True if isContainerType()
or ResolvedType.isReferenceType()
return true.public final boolean isTypeOrSubTypeOf(java.lang.Class<?> clz)
public final boolean isTypeOrSuperTypeOf(java.lang.Class<?> clz)
public boolean isAbstract()
isAbstract
in class ResolvedType
public boolean isConcrete()
isConcrete
in class ResolvedType
public boolean isThrowable()
isThrowable
in class ResolvedType
public boolean isArrayType()
isArrayType
in class ResolvedType
public final boolean isEnumType()
Enum.class.isAssignableFrom(getRawClass())that is, return
true
if the underlying type erased class is Enum
or one its subtypes (Enum implementations).isEnumType
in class ResolvedType
public final boolean isEnumImplType()
isEnumType()
except does NOT return true
for Enum
(since that is not Enum implementation type).public final boolean isRecordType()
public final boolean isInterface()
isInterface
in class ResolvedType
public final boolean isPrimitive()
isPrimitive
in class ResolvedType
public final boolean isFinal()
isFinal
in class ResolvedType
public abstract boolean isContainerType()
isContainerType
in class ResolvedType
public boolean isCollectionLikeType()
isCollectionLikeType
in class ResolvedType
Collection
type,
or something similar (meaning it has at least one type parameter,
which describes type of contents)public boolean isMapLikeType()
isMapLikeType
in class ResolvedType
Map
type,
or something similar (meaning it has at least two type parameter;
first one describing key type, second value type)public final boolean isJavaLangObject()
getRawClass() == Object.class
and used to figure if we basically have "untyped" type object.public final boolean useStaticType()
public boolean hasGenericTypes()
ResolvedType
hasGenericTypes
in class ResolvedType
True
if this type has generic type parameters, false
if notpublic JavaType getKeyType()
ResolvedType
getKeyType
in class ResolvedType
null
if nonepublic JavaType getContentType()
ResolvedType
getContentType
in class ResolvedType
null
if nonepublic JavaType getReferencedType()
ResolvedType
getReferencedType
in class ResolvedType
null
if not.public abstract int containedTypeCount()
ResolvedType
containedTypeCount
in class ResolvedType
public abstract JavaType containedType(int index)
ResolvedType
containedType
in class ResolvedType
index
- Index of contained type to return@Deprecated public abstract java.lang.String containedTypeName(int index)
ResolvedType
containedTypeName
in class ResolvedType
index
- Index of contained type to return@Deprecated public java.lang.Class<?> getParameterSource()
getParameterSource
in class ResolvedType
public JavaType containedTypeOrUnknown(int index)
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 to java.lang.Object
basically).public abstract TypeBindings getBindings()
public abstract JavaType findSuperType(java.lang.Class<?> erasedTarget)
public abstract JavaType getSuperClass()
public abstract java.util.List<JavaType> getInterfaces()
public abstract JavaType[] findTypeParameters(java.lang.Class<?> expType)
public <T> T getValueHandler()
public <T> T getTypeHandler()
public java.lang.Object getContentValueHandler()
public java.lang.Object getContentTypeHandler()
public boolean hasValueHandler()
public boolean hasHandlers()
getValueHandler()
or getTypeHandler()
;
that is, are there any non-standard handlers associated with this
type object.public java.lang.String getGenericSignature()
getErasedSignature()
,
in that generic information can be automatically removed
if necessary (just remove outermost
angle brackets along with content inside)public abstract java.lang.StringBuilder getGenericSignature(java.lang.StringBuilder sb)
sb
- StringBuilder to append signature topublic java.lang.String getErasedSignature()
public abstract java.lang.StringBuilder getErasedSignature(java.lang.StringBuilder sb)
sb
- StringBuilder to append signature topublic abstract java.lang.String toString()
toString
in class java.lang.Object
public abstract boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public final int hashCode()
hashCode
in class java.lang.Object
Copyright © 2010 - 2023 Adobe. All Rights Reserved