|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.core.convert.TypeDescriptor
public class TypeDescriptor
Context about a type to convert from or to.
Constructor Summary | |
---|---|
TypeDescriptor(Field field)
Create a new type descriptor from a Field . |
|
TypeDescriptor(MethodParameter methodParameter)
Create a new type descriptor from a MethodParameter . |
|
TypeDescriptor(Property property)
Create a new type descriptor from a Property . |
Method Summary | |
---|---|
static TypeDescriptor |
collection(Class<?> collectionType,
TypeDescriptor elementTypeDescriptor)
Create a new type descriptor from a java.util.Collection type. |
TypeDescriptor |
elementTypeDescriptor(Object element)
If this type is a Collection or an Array, creates a element TypeDescriptor from the provided collection or array element. |
boolean |
equals(Object obj)
|
static TypeDescriptor |
forObject(Object source)
Create a new type descriptor for an object. |
Annotation |
getAnnotation(Class<? extends Annotation> annotationType)
Obtain the annotation associated with this type descriptor of the specified type. |
Annotation[] |
getAnnotations()
The annotations associated with this type descriptor, if any. |
Class<?> |
getElementType()
Deprecated. in Spring 3.1 in favor of getElementTypeDescriptor() . |
TypeDescriptor |
getElementTypeDescriptor()
If this type is an array, returns the array's component type. |
Class<?> |
getMapKeyType()
Deprecated. in Spring 3.1 in favor of getMapKeyTypeDescriptor() . |
TypeDescriptor |
getMapKeyTypeDescriptor()
If this type is a Map and its key type is parameterized, returns the map's key type. |
Class<?> |
getMapValueType()
Deprecated. in Spring 3.1 in favor of getMapValueTypeDescriptor() . |
TypeDescriptor |
getMapValueTypeDescriptor()
If this type is a Map and its value type is parameterized, returns the map's value type. |
String |
getName()
Returns the name of this type: the fully qualified class name. |
Class<?> |
getObjectType()
Variation of getType() that accounts for a primitive type by returning its object wrapper type. |
Class<?> |
getType()
The type of the backing class, method parameter, field, or property described by this TypeDescriptor. |
int |
hashCode()
|
boolean |
isArray()
Is this type an array type? |
boolean |
isAssignableTo(TypeDescriptor typeDescriptor)
Returns true if an object of this type descriptor can be assigned to the location described by the given type descriptor. |
boolean |
isCollection()
Is this type a Collection type? |
boolean |
isMap()
Is this type a Map type? |
boolean |
isPrimitive()
Is this type a primitive type? |
static TypeDescriptor |
map(Class<?> mapType,
TypeDescriptor keyTypeDescriptor,
TypeDescriptor valueTypeDescriptor)
Create a new type descriptor from a java.util.Map type. |
TypeDescriptor |
mapKeyTypeDescriptor(Object mapKey)
If this type is a Map , creates a mapKey TypeDescriptor from the provided map key. |
TypeDescriptor |
mapValueTypeDescriptor(Object mapValue)
If this type is a Map , creates a mapValue TypeDescriptor from the provided map value. |
TypeDescriptor |
narrow(Object value)
Narrows this TypeDescriptor by setting its type to the class of the provided value. |
static TypeDescriptor |
nested(Field field,
int nestingLevel)
Creates a type descriptor for a nested type declared within the field. |
static TypeDescriptor |
nested(MethodParameter methodParameter,
int nestingLevel)
Creates a type descriptor for a nested type declared within the method parameter. |
static TypeDescriptor |
nested(Property property,
int nestingLevel)
Creates a type descriptor for a nested type declared within the property. |
String |
toString()
|
static TypeDescriptor |
valueOf(Class<?> type)
Create a new type descriptor from the given type. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TypeDescriptor(MethodParameter methodParameter)
MethodParameter
.
Use this constructor when a source or target conversion point is a constructor parameter, method parameter, or method return value.
methodParameter
- the method parameterpublic TypeDescriptor(Field field)
Field
.
Use this constructor when source or target conversion point is a field.
field
- the fieldpublic TypeDescriptor(Property property)
Property
.
Use this constructor when a source or target conversion point is a property on a Java class.
property
- the propertyMethod Detail |
---|
public static TypeDescriptor valueOf(Class<?> type)
forObject(Object)
for constructing type descriptors from source objects, as it handles the null object case.
type
- the class
public static TypeDescriptor collection(Class<?> collectionType, TypeDescriptor elementTypeDescriptor)
collectionType
- the collection type, which must implement Collection
.elementTypeDescriptor
- a descriptor for the collection's element type, used to convert collection elements
public static TypeDescriptor map(Class<?> mapType, TypeDescriptor keyTypeDescriptor, TypeDescriptor valueTypeDescriptor)
mapType
- the map type, which must implement Map
.keyTypeDescriptor
- a descriptor for the map's key type, used to convert map keysvalueTypeDescriptor
- the map's value type, used to convert map values
public static TypeDescriptor nested(MethodParameter methodParameter, int nestingLevel)
public static TypeDescriptor nested(Field field, int nestingLevel)
public static TypeDescriptor nested(Property property, int nestingLevel)
public static TypeDescriptor forObject(Object source)
valueOf(Class)
to build a TypeDescriptor from the object's class.
object
- the source object
public Class<?> getType()
getObjectType()
for a variation of this operation that resolves primitive types to their corresponding Object types if necessary.
null
if this is TypeDescriptor#NULL
getObjectType()
public Class<?> getObjectType()
getType()
that accounts for a primitive type by returning its object wrapper type.
This is useful for conversion service implementations that wish to normalize to object-based types and not work with primitive types directly.
public TypeDescriptor narrow(Object value)
TypeDescriptor
by setting its type to the class of the provided value.
If the value is null, no narrowing is performed and this TypeDescriptor is returned unchanged.
Designed to be called by binding frameworks when they read property, field, or method return values.
Allows such frameworks to narrow a TypeDescriptor built from a declared property, field, or method return value type.
For example, a field declared as java.lang.Object would be narrowed to java.util.HashMap if it was set to a java.util.HashMap value.
The narrowed TypeDescriptor can then be used to convert the HashMap to some other type.
Annotation and nested type context is preserved by the narrowed copy.
value
- the value to use for narrowing this type descriptor
public String getName()
public boolean isPrimitive()
public Annotation[] getAnnotations()
public Annotation getAnnotation(Class<? extends Annotation> annotationType)
public boolean isAssignableTo(TypeDescriptor typeDescriptor)
For arrays, collections, and maps, element and key/value types are checked if declared. For example, a List<String> field value is assignable to a Collection<CharSequence> field, but List<Number> is not assignable to List<Integer>.
getObjectType()
public boolean isCollection()
Collection
type?
public boolean isArray()
public TypeDescriptor getElementTypeDescriptor()
Collection
and it is parameterized, returns the Collection's element type.
If the Collection is not parameterized, returns null indicating the element type is not declared.
null
if this type is a Collection but its element type is not parameterized.
IllegalStateException
- if this type is not a java.util.Collection or Array typepublic TypeDescriptor elementTypeDescriptor(Object element)
Collection
or an Array, creates a element TypeDescriptor from the provided collection or array element.
Narrows the elementType
property to the class of the provided collection or array element.
For example, if this describes a java.util.List<java.lang.Number< and the element argument is a java.lang.Integer, the returned TypeDescriptor will be java.lang.Integer.
If this describes a java.util.List<?> and the element argument is a java.lang.Integer, the returned TypeDescriptor will be java.lang.Integer as well.
Annotation and nested type context will be preserved in the narrowed TypeDescriptor that is returned.
element
- the collection or array element
IllegalStateException
- if this type is not a java.util.Collection or Array typenarrow(Object)
public boolean isMap()
Map
type?
public TypeDescriptor getMapKeyTypeDescriptor()
Map
and its key type is parameterized, returns the map's key type.
If the Map's key type is not parameterized, returns null indicating the key type is not declared.
null
if this type is a Map but its key type is not parameterized.
IllegalStateException
- if this type is not a java.util.Map.public TypeDescriptor mapKeyTypeDescriptor(Object mapKey)
Map
, creates a mapKey TypeDescriptor
from the provided map key.
Narrows the mapKeyType
property to the class of the provided map key.
For example, if this describes a java.util.Map<java.lang.Number, java.lang.String< and the key argument is a java.lang.Integer, the returned TypeDescriptor will be java.lang.Integer.
If this describes a java.util.Map<?, ?> and the key argument is a java.lang.Integer, the returned TypeDescriptor will be java.lang.Integer as well.
Annotation and nested type context will be preserved in the narrowed TypeDescriptor that is returned.
mapKey
- the map key
IllegalStateException
- if this type is not a java.util.Map.narrow(Object)
public TypeDescriptor getMapValueTypeDescriptor()
Map
and its value type is parameterized, returns the map's value type.
If the Map's value type is not parameterized, returns null indicating the value type is not declared.
null
if this type is a Map but its value type is not parameterized.
IllegalStateException
- if this type is not a java.util.Map.public TypeDescriptor mapValueTypeDescriptor(Object mapValue)
Map
, creates a mapValue TypeDescriptor
from the provided map value.
Narrows the mapValueType
property to the class of the provided map value.
For example, if this describes a java.util.Map<java.lang.String, java.lang.Number< and the value argument is a java.lang.Integer, the returned TypeDescriptor will be java.lang.Integer.
If this describes a java.util.Map<?, ?> and the value argument is a java.lang.Integer, the returned TypeDescriptor will be java.lang.Integer as well.
Annotation and nested type context will be preserved in the narrowed TypeDescriptor that is returned.
mapValue
- the map value
IllegalStateException
- if this type is not a java.util.Map.public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
@Deprecated public Class<?> getElementType()
getElementTypeDescriptor()
.
getType()
for the elementTypeDescriptor
.
IllegalStateException
- if this type is not a java.util.Collection or Array type@Deprecated public Class<?> getMapKeyType()
getMapKeyTypeDescriptor()
.
getType()
for the mapKeyTypeDescriptor
.
IllegalStateException
- if this type is not a java.util.Map.@Deprecated public Class<?> getMapValueType()
getMapValueTypeDescriptor()
.
getType()
for the mapValueTypeDescriptor
.
IllegalStateException
- if this type is not a java.util.Map.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |