support for empty collection->collection. map->map, collection->array conversion

This commit is contained in:
Keith Donald
2011-01-07 03:24:24 +00:00
parent 42403a37c3
commit 8e23685a6d
4 changed files with 63 additions and 6 deletions

View File

@@ -49,7 +49,11 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return this.conversionService.canConvert(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor());
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
if (Object.class.equals(sourceElementType.getType())) {
return true;
}
return this.conversionService.canConvert(sourceElementType, targetType.getElementTypeDescriptor());
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

View File

@@ -43,7 +43,11 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return this.conversionService.canConvert(sourceType.getElementTypeDescriptor(), targetType);
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
if (Object.class.equals(sourceElementType.getType())) {
return true;
}
return this.conversionService.canConvert(sourceElementType, targetType);
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

View File

@@ -49,6 +49,14 @@ final class MapToMapConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
TypeDescriptor sourceKeyType = sourceType.getMapKeyTypeDescriptor();
TypeDescriptor targetKeyType = targetType.getMapKeyTypeDescriptor();
TypeDescriptor sourceValueType = sourceType.getMapValueTypeDescriptor();
TypeDescriptor targetValueType = targetType.getMapValueTypeDescriptor();
if (Object.class.equals(sourceKeyType.getType()) && Object.class.equals(sourceValueType.getType())
|| Object.class.equals(targetKeyType.getType()) && Object.class.equals(targetValueType.getType())) {
return true;
}
return this.conversionService.canConvert(sourceType.getMapKeyTypeDescriptor(), targetType.getMapKeyTypeDescriptor()) &&
this.conversionService.canConvert(sourceType.getMapValueTypeDescriptor(), targetType.getMapValueTypeDescriptor());
}