public class

TypeDescriptor

extends Object
java.lang.Object
   ↳ org.springframework.core.convert.TypeDescriptor
Known Direct Subclasses

Class Overview

Context about a type to convert to.

Summary

Fields
public static final TypeDescriptor NULL Constant defining a TypeDescriptor for a null value
Public Constructors
TypeDescriptor(MethodParameter methodParameter)
Create a new type descriptor from a method or constructor parameter.
TypeDescriptor(Field field)
Create a new type descriptor for a field.
Protected Constructors
TypeDescriptor(Class<?> nestedType, MethodParameter methodParameter)
Public Methods
TypeDescriptor applyIndexedObject(Object object)
Create a copy of this nested type descriptor and apply the specific type information from the indexed object.
String asString()
A textual representation of the type descriptor (eg.
boolean equals(Object obj)
static TypeDescriptor forNestedType(Class<?> nestedType, MethodParameter methodParameter)
Create a new type descriptor for a nested type declared on an array, collection, or map-based method parameter.
static TypeDescriptor forNestedType(MethodParameter methodParameter)
Create a new type descriptor for a nested type declared on an array, collection, or map-based method parameter.
static TypeDescriptor forObject(Object object)
Create a new type descriptor for an object.
Annotation getAnnotation(Class<? extends Annotation> annotationType)
Obtain the annotation associated with the wrapped parameter/field, if any.
synchronized Annotation[] getAnnotations()
Obtain the annotations associated with the wrapped parameter/field, if any.
Class<?> getElementType()
If this type is an array type or Collection type, returns the underlying element type.
synchronized TypeDescriptor getElementTypeDescriptor()
Return the element type as a type descriptor.
Class<?> getMapKeyType()
Determine the generic key type of the wrapped Map parameter/field, if any.
synchronized TypeDescriptor getMapKeyTypeDescriptor()
Returns map key type as a type descriptor.
Class<?> getMapValueType()
Determine the generic value type of the wrapped Map parameter/field, if any.
synchronized TypeDescriptor getMapValueTypeDescriptor()
Returns map value type as a type descriptor.
MethodParameter getMethodParameter()
Exposes the underlying MethodParameter providing context for this TypeDescriptor.
String getName()
Returns the name of this type: the fully qualified class name.
Class<?> getObjectType()
Determine the declared type of the wrapped parameter/field.
Class<?> getType()
Determine the declared (non-generic) type of the wrapped parameter/field.
int hashCode()
boolean isArray()
Is this type an array type?
boolean isAssignableTo(TypeDescriptor targetType)
Returns true if an object of this type can be assigned to a reference of given targetType.
boolean isCollection()
Is this type a Collection type?
boolean isMap()
Is this type a Map type?
boolean isPrimitive()
Is this type a primitive type?
String toString()
static TypeDescriptor valueOf(Class<?> type)
Create a new type descriptor for the given class.
Protected Methods
TypeDescriptor newNestedTypeDescriptor(Class<?> nestedType, MethodParameter nested)
Annotation[] resolveAnnotations()
static Class<?> resolveNestedType(MethodParameter methodParameter)
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final TypeDescriptor NULL

Also: SpringCore

Constant defining a TypeDescriptor for a null value

Public Constructors

public TypeDescriptor (MethodParameter methodParameter)

Also: SpringCore

Create a new type descriptor from a method or constructor parameter. Use this constructor when a target conversion point originates from a method parameter, such as a setter method argument.

Parameters
methodParameter the MethodParameter to wrap

public TypeDescriptor (Field field)

Also: SpringCore

Create a new type descriptor for a field. Use this constructor when a target conversion point originates from a field.

Parameters
field the field to wrap

Protected Constructors

protected TypeDescriptor (Class<?> nestedType, MethodParameter methodParameter)

Also: SpringCore

Public Methods

public TypeDescriptor applyIndexedObject (Object object)

Also: SpringCore

Create a copy of this nested type descriptor and apply the specific type information from the indexed object. Used to support collection and map indexing scenarios, where the indexer has a reference to the indexed type descriptor but needs to ensure its type actually represents the indexed object type. This is necessary to support type conversion during index object binding operations.

public String asString ()

Also: SpringCore

A textual representation of the type descriptor (eg. Map) for use in messages.

public boolean equals (Object obj)

public static TypeDescriptor forNestedType (Class<?> nestedType, MethodParameter methodParameter)

Also: SpringCore

Create a new type descriptor for a nested type declared on an array, collection, or map-based method parameter. Use this factory method when you've resolved a nested source object such as a collection element or map value and wish to have it converted.

Parameters
nestedType the nested type
methodParameter the method parameter declaring the collection or map
Returns
  • the nested type descriptor

public static TypeDescriptor forNestedType (MethodParameter methodParameter)

Also: SpringCore

Create a new type descriptor for a nested type declared on an array, collection, or map-based method parameter. Use this factory method when you've resolved a nested source object such as a collection element or map value and wish to have it converted.

Parameters
methodParameter the method parameter declaring the collection or map
Returns
  • the nested type descriptor

public static TypeDescriptor forObject (Object object)

Also: SpringCore

Create a new type descriptor for an object. Use this factory method to introspect a source object's type before asking the conversion system to convert it to some another type. Builds in population of nested type descriptors for collection and map objects through object introspection. If the object is null, returns NULL. If the object is not a collection, simply calls valueOf(Class). If the object is a collection, this factory method will derive the element type(s) by introspecting the collection.

Parameters
object the source object
Returns
  • the type descriptor

public Annotation getAnnotation (Class<? extends Annotation> annotationType)

Also: SpringCore

Obtain the annotation associated with the wrapped parameter/field, if any.

public synchronized Annotation[] getAnnotations ()

Also: SpringCore

Obtain the annotations associated with the wrapped parameter/field, if any.

public Class<?> getElementType ()

Also: SpringCore

If this type is an array type or Collection type, returns the underlying element type. Returns null if the type is neither an array or collection.

public synchronized TypeDescriptor getElementTypeDescriptor ()

Also: SpringCore

Return the element type as a type descriptor.

public Class<?> getMapKeyType ()

Also: SpringCore

Determine the generic key type of the wrapped Map parameter/field, if any.

Returns
  • the generic type, or null if none

public synchronized TypeDescriptor getMapKeyTypeDescriptor ()

Also: SpringCore

Returns map key type as a type descriptor.

public Class<?> getMapValueType ()

Also: SpringCore

Determine the generic value type of the wrapped Map parameter/field, if any.

Returns
  • the generic type, or null if none

public synchronized TypeDescriptor getMapValueTypeDescriptor ()

Also: SpringCore

Returns map value type as a type descriptor.

public MethodParameter getMethodParameter ()

Also: SpringCore

Exposes the underlying MethodParameter providing context for this TypeDescriptor. Used to support legacy code scenarios where callers are already using the MethodParameter API (BeanWrapper). In general, favor use of the TypeDescriptor API over the MethodParameter API as it is independent of type context location. May be null if no MethodParameter was provided when this TypeDescriptor was constructed.

public String getName ()

Also: SpringCore

Returns the name of this type: the fully qualified class name.

public Class<?> getObjectType ()

Also: SpringCore

Determine the declared type of the wrapped parameter/field. Returns the Object wrapper type if the underlying type is a primitive.

public Class<?> getType ()

Also: SpringCore

Determine the declared (non-generic) type of the wrapped parameter/field.

Returns
  • the declared type, or null if this is NULL

public int hashCode ()

public boolean isArray ()

Also: SpringCore

Is this type an array type?

public boolean isAssignableTo (TypeDescriptor targetType)

Also: SpringCore

Returns true if an object of this type can be assigned to a reference of given targetType.

Parameters
targetType the target type
Returns
  • true if this type is assignable to the target

public boolean isCollection ()

Also: SpringCore

Is this type a Collection type?

public boolean isMap ()

Also: SpringCore

Is this type a Map type?

public boolean isPrimitive ()

Also: SpringCore

Is this type a primitive type?

public String toString ()

public static TypeDescriptor valueOf (Class<?> type)

Also: SpringCore

Create a new type descriptor for the given class. Use this to instruct the conversion system to convert to an object to a specific target type, when no type location such as a method parameter or field is available to provide additional conversion context. Generally prefer use of forObject(Object) for constructing source type descriptors for source objects.

Parameters
type the class
Returns
  • the type descriptor

Protected Methods

protected TypeDescriptor newNestedTypeDescriptor (Class<?> nestedType, MethodParameter nested)

Also: SpringCore

protected Annotation[] resolveAnnotations ()

Also: SpringCore

protected static Class<?> resolveNestedType (MethodParameter methodParameter)

Also: SpringCore