public abstract class JavaType extends ResolvedType implements Serializable, 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 | Field and Description |
---|---|
protected boolean |
_asStatic
Whether entities defined with this type should be handled using
static typing (as opposed to dynamic runtime type) or not.
|
protected 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).
|
protected int |
_hash |
protected Object |
_typeHandler
Optional handler that can be attached to indicate how to handle
additional type metadata associated with this type.
|
protected Object |
_valueHandler
Optional handler (codec) that can be attached to indicate
what to use for handling (serializing, deserializing) values of
this specific type.
|
Modifier | Constructor and Description |
---|---|
protected |
JavaType(Class<?> raw,
int additionalHash,
Object valueHandler,
Object typeHandler,
boolean asStatic) |
protected |
JavaType(JavaType base)
Copy-constructor used when refining/upgrading type instances.
|
Modifier and Type | Method and Description |
---|---|
protected abstract JavaType |
_narrow(Class<?> subclass)
Deprecated.
|
abstract JavaType |
containedType(int index) |
abstract int |
containedTypeCount() |
abstract 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(Object o) |
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.
|
abstract JavaType[] |
findTypeParameters(Class<?> expType)
Method that may be used to find paramaterization this type has for
given type-erased generic target type.
|
JavaType |
forcedNarrowBy(Class<?> subclass)
Deprecated.
|
abstract TypeBindings |
getBindings() |
JavaType |
getContentType() |
Object |
getContentTypeHandler() |
Object |
getContentValueHandler() |
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 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.
|
String |
getGenericSignature()
Method for accessing signature that contains generic
type information, in form compatible with JVM 1.5
as per JLS.
|
abstract StringBuilder |
getGenericSignature(StringBuilder sb) |
abstract List<JavaType> |
getInterfaces()
Accessor for finding fully resolved interfaces this type implements,
if any; empty array if none.
|
JavaType |
getKeyType() |
Class<?> |
getParameterSource()
Deprecated.
|
Class<?> |
getRawClass() |
JavaType |
getReferencedType() |
abstract JavaType |
getSuperClass()
Accessor for finding fully resolved parent class of this type,
if it has one; null if not.
|
<T> T |
getTypeHandler()
Method for accessing type handler associated with this type, if any
|
<T> T |
getValueHandler()
Method for accessing value handler associated with this type, if any
|
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() |
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(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 |
isEnumType() |
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 |
isThrowable() |
boolean |
isTypeOrSubTypeOf(Class<?> clz) |
boolean |
isTypeOrSuperTypeOf(Class<?> clz) |
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.
|
abstract 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(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 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.
|
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).
|
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(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 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.
|
isReferenceType, toCanonical
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getTypeName
protected final Class<?> _class
protected final int _hash
protected final Object _valueHandler
Note: untyped (i.e. caller has to cast) because it is used for different kinds of handlers, with unrelated types.
protected final Object _typeHandler
Note: untyped (i.e. caller has to cast) because it is used for different kinds of handlers, with unrelated types.
protected final boolean _asStatic
protected JavaType(Class<?> raw, int additionalHash, Object valueHandler, Object typeHandler, boolean asStatic)
raw
- "Raw" (type-erased) class for this typeadditionalHash
- Additional hash code to use, in addition
to hash code of the class nameprotected JavaType(JavaType base)
public abstract JavaType withTypeHandler(Object h)
public abstract JavaType withContentTypeHandler(Object h)
public abstract JavaType withValueHandler(Object h)
public abstract JavaType withContentValueHandler(Object h)
public JavaType withHandlersFrom(JavaType src)
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 refine(Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces)
@Deprecated public JavaType forcedNarrowBy(Class<?> subclass)
TypeFactory
, not directly via JavaType
.@Deprecated protected abstract JavaType _narrow(Class<?> subclass)
public final Class<?> getRawClass()
getRawClass
in class ResolvedType
public final boolean hasRawClass(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(Class<?> clz)
public final boolean isTypeOrSuperTypeOf(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()
isEnumType
in class ResolvedType
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()
hasGenericTypes
in class ResolvedType
public JavaType getKeyType()
getKeyType
in class ResolvedType
public JavaType getContentType()
getContentType
in class ResolvedType
public JavaType getReferencedType()
getReferencedType
in class ResolvedType
public abstract int containedTypeCount()
containedTypeCount
in class ResolvedType
public abstract JavaType containedType(int index)
containedType
in class ResolvedType
@Deprecated public abstract String containedTypeName(int index)
containedTypeName
in class ResolvedType
@Deprecated public 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(Class<?> erasedTarget)
public abstract JavaType getSuperClass()
public abstract List<JavaType> getInterfaces()
public abstract JavaType[] findTypeParameters(Class<?> expType)
public <T> T getValueHandler()
public <T> T getTypeHandler()
public Object getContentValueHandler()
public 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 String getGenericSignature()
getErasedSignature()
,
in that generic information can be automatically removed
if necessary (just remove outermost
angle brackets along with content inside)public abstract StringBuilder getGenericSignature(StringBuilder sb)
sb
- StringBuilder to append signature topublic String getErasedSignature()
public abstract StringBuilder getErasedSignature(StringBuilder sb)
sb
- StringBuilder to append signature toCopyright © 2008–2018 FasterXML. All rights reserved.