full support for formatters on array/collection elements (SPR-6504)
This commit is contained in:
@@ -20,6 +20,7 @@ package org.springframework.core.convert;
|
||||
* Thrown when an attempt to execute a type conversion fails.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*/
|
||||
public final class ConversionFailedException extends ConversionException {
|
||||
@@ -37,8 +38,8 @@ public final class ConversionFailedException extends ConversionException {
|
||||
* @param cause the cause of the conversion failure
|
||||
*/
|
||||
public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) {
|
||||
super("Unable to convert value " + value + " from type [" + sourceType.getName() + "] to type [" +
|
||||
targetType.getName() + "]; reason = '" + cause.getMessage() + "'", cause);
|
||||
super("Unable to convert value " + value + " from type '" + sourceType.getName() +
|
||||
"' to type '" + targetType.getName() + "'", cause);
|
||||
this.sourceType = sourceType;
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,19 @@ public class TypeDescriptor {
|
||||
this.methodParameter = methodParameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new type descriptor from a method or constructor parameter.
|
||||
* <p>Use this constructor when a target conversion point originates from a method parameter,
|
||||
* such as a setter method argument.
|
||||
* @param methodParameter the MethodParameter to wrap
|
||||
* @param type the specific type to expose (may be an array/collection element)
|
||||
*/
|
||||
protected TypeDescriptor(MethodParameter methodParameter, Class type) {
|
||||
Assert.notNull(methodParameter, "MethodParameter must not be null");
|
||||
this.methodParameter = methodParameter;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new type descriptor for a field.
|
||||
* Use this constructor when a target conversion point originates from a field.
|
||||
@@ -158,16 +171,11 @@ public class TypeDescriptor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this type; the fully qualified classname.
|
||||
* Returns the name of this type: the fully qualified class name.
|
||||
*/
|
||||
public String getName() {
|
||||
Class<?> type = getType();
|
||||
if (type != null) {
|
||||
return getType().getName();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return (type != null ? ClassUtils.getQualifiedName(type) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,17 +404,16 @@ public class TypeDescriptor {
|
||||
|
||||
public String toString() {
|
||||
if (this == TypeDescriptor.NULL) {
|
||||
return "[TypeDescriptor.NULL]";
|
||||
return "TypeDescriptor.NULL";
|
||||
}
|
||||
else {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("[TypeDescriptor ");
|
||||
builder.append("TypeDescriptor ");
|
||||
Annotation[] anns = getAnnotations();
|
||||
for (Annotation ann : anns) {
|
||||
builder.append("@").append(ann.annotationType().getName()).append(' ');
|
||||
}
|
||||
builder.append(getType().getName());
|
||||
builder.append("]");
|
||||
builder.append(ClassUtils.getQualifiedName(getType()));
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user