avoid ConverterNotFoundException if source object is assignable to target type

This commit is contained in:
Juergen Hoeller
2010-06-15 09:35:39 +00:00
parent bd88bbab4a
commit 7b189d1124
2 changed files with 28 additions and 2 deletions

View File

@@ -172,7 +172,13 @@ public class GenericConversionService implements ConversionService, ConverterReg
}
GenericConverter converter = getConverter(sourceType, targetType);
if (converter == null) {
throw new ConverterNotFoundException(sourceType, targetType);
if (targetType.getType().isInstance(source)) {
logger.debug("No converter found - returning assignable source object as-is");
return source;
}
else {
throw new ConverterNotFoundException(sourceType, targetType);
}
}
Object result = ConversionUtils.invokeConverter(converter, source, sourceType, targetType);
if (logger.isDebugEnabled()) {