ConversionService is able to work with "Collections.emptyList()" as target type (again; SPR-7293)

This commit is contained in:
Juergen Hoeller
2011-12-06 21:17:25 +00:00
parent 5ab2bf16a5
commit e0d922d352
3 changed files with 16 additions and 0 deletions

View File

@@ -60,6 +60,9 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
}
boolean copyRequired = !targetType.getType().isInstance(source);
Collection<?> sourceCollection = (Collection<?>) source;
if (!copyRequired && sourceCollection.isEmpty()) {
return sourceCollection;
}
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), sourceCollection.size());
if (targetType.getElementTypeDescriptor() == null) {
for (Object element : sourceCollection) {

View File

@@ -59,6 +59,9 @@ final class MapToMapConverter implements ConditionalGenericConverter {
}
boolean copyRequired = !targetType.getType().isInstance(source);
Map<Object, Object> sourceMap = (Map<Object, Object>) source;
if (!copyRequired && sourceMap.isEmpty()) {
return sourceMap;
}
Map<Object, Object> targetMap = CollectionFactory.createMap(targetType.getType(), sourceMap.size());
for (Map.Entry<Object, Object> entry : sourceMap.entrySet()) {
Object sourceKey = entry.getKey();