Avoid NPE in ObjectToObjectConverter
Bypass ObjectToObject conversion when source and object types are identical and protect against a null source object. Prior to this commit the TypeDescriptor was used to determine if conversion was necessary. This caused issues when comparing a descriptor with annotations to one without. The updated code now compares using TypeDescriptor.getType(). The ObjectToObject converter will now no longer attempt to convert null source objects. Issue: SPR-9933
This commit is contained in:
@@ -48,10 +48,17 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
|
||||
}
|
||||
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return !sourceType.equals(targetType) && hasValueOfMethodOrConstructor(targetType.getType(), sourceType.getType());
|
||||
if (sourceType.getType().equals(targetType.getType())) {
|
||||
// no conversion required
|
||||
return false;
|
||||
}
|
||||
return hasValueOfMethodOrConstructor(targetType.getType(), sourceType.getType());
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
Class<?> sourceClass = sourceType.getType();
|
||||
Class<?> targetClass = targetType.getType();
|
||||
Method method = getValueOfMethodOn(targetClass, sourceClass);
|
||||
|
||||
Reference in New Issue
Block a user