ConversionExecutor now checks for assignment compatible types (SWF-337).
This commit is contained in:
@@ -103,6 +103,20 @@ public class ConversionException extends NestedRuntimeException {
|
||||
this.targetClass = null; // not available
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new conversion exception.
|
||||
* @param sourceClass the source type
|
||||
* @param value the value we tried to convert
|
||||
* @param targetClass the target type
|
||||
* @param message a descriptive message
|
||||
*/
|
||||
public ConversionException(Class sourceClass, Object value, Class targetClass, String message) {
|
||||
super(message);
|
||||
this.sourceClass = sourceClass;
|
||||
this.value = value;
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source type.
|
||||
*/
|
||||
|
||||
@@ -98,8 +98,13 @@ public class ConversionExecutor {
|
||||
* behavior of the converter
|
||||
*/
|
||||
public Object execute(Object source, ConversionContext context) throws ConversionException {
|
||||
if (source != null) {
|
||||
Assert.isInstanceOf(sourceClass, source, "Not of source type: ");
|
||||
if (getTargetClass().isInstance(source)) {
|
||||
// source is already assignment compatible with target class
|
||||
return source;
|
||||
}
|
||||
if (source != null && !getSourceClass().isInstance(source)) {
|
||||
throw new ConversionException(getSourceClass(), source, getTargetClass(),
|
||||
"Source object '" + source + "' is expected to be a " + getSourceClass());
|
||||
}
|
||||
return converter.convert(source, targetClass, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user