ConversionService is able to work with "Collections.emptyList()" as target type (again; SPR-7293)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user