restored original ConversionService behavior with respect to empty collections/maps (SPR-7728)

This commit is contained in:
Juergen Hoeller
2011-06-13 22:03:00 +00:00
parent 5f3f30fdb4
commit 58d68cef98
3 changed files with 8 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,9 +58,6 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
return null;
}
Collection<?> sourceCollection = (Collection<?>) source;
if (sourceCollection.isEmpty()) {
return sourceCollection;
}
Collection target = CollectionFactory.createCollection(targetType.getType(), sourceCollection.size());
for (Object sourceElement : sourceCollection) {
Object targetElement = this.conversionService.convert(sourceElement,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,9 +59,6 @@ final class MapToMapConverter implements ConditionalGenericConverter {
return null;
}
Map<?, ?> sourceMap = (Map<?, ?>) source;
if (sourceMap.isEmpty()) {
return sourceMap;
}
Map targetMap = CollectionFactory.createMap(targetType.getType(), sourceMap.size());
for (Object entry : sourceMap.entrySet()) {
Map.Entry sourceMapEntry = (Map.Entry) entry;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,18 +24,19 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.io.Resource;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.Resource;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*;
/**
* @author Keith Donald
* @author Juergen Hoeller
@@ -271,9 +272,7 @@ public class GenericConversionServiceTests {
GenericConversionService service = ConversionServiceFactory.createDefaultConversionService();
List list = Collections.emptyList();
List result = service.convert(list, List.class);
assertSame(list, result);
result = service.convert(list, list.getClass());
assertSame(list, result);
assertTrue(result.isEmpty());
}
@Test
@@ -281,9 +280,7 @@ public class GenericConversionServiceTests {
GenericConversionService service = ConversionServiceFactory.createDefaultConversionService();
Map map = Collections.emptyMap();
Map result = service.convert(map, Map.class);
assertSame(map, result);
result = service.convert(map, map.getClass());
assertSame(map, result);
assertTrue(result.isEmpty());
}
@Test