Browse Source

Relaxed getElementTypeDescriptor assertion to not insist on a ResolvableType-known array

Issue: SPR-11608
pull/499/head
Juergen Hoeller 11 years ago
parent
commit
b9bac1d3b6
  1. 2
      spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
  2. 19
      spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java

2
spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

@ -325,9 +325,7 @@ public class TypeDescriptor implements Serializable { @@ -325,9 +325,7 @@ public class TypeDescriptor implements Serializable {
if (this.resolvableType.isArray()) {
return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations);
}
Assert.state(isCollection(), "Not an array or java.util.Collection");
return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric());
}
/**

19
spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -53,7 +53,8 @@ import static org.junit.Assert.*; @@ -53,7 +53,8 @@ import static org.junit.Assert.*;
*/
public class DefaultConversionTests {
private DefaultConversionService conversionService = new DefaultConversionService();
private final DefaultConversionService conversionService = new DefaultConversionService();
@Test
public void testStringToCharacter() {
@ -777,6 +778,16 @@ public class DefaultConversionTests { @@ -777,6 +778,16 @@ public class DefaultConversionTests {
assertThat(converted, equalTo(new char[] { 'a', 'b', 'c' }));
}
@Test
public void multidimensionalArrayToListConversionShouldConvertEntriesCorrectly() {
String[][] grid = new String[][] { new String[] { "1", "2", "3", "4" }, new String[] { "5", "6", "7", "8" },
new String[] { "9", "10", "11", "12" } };
List<String[]> converted = conversionService.convert(grid, List.class);
String[][] convertedBack = conversionService.convert(converted, String[][].class);
assertArrayEquals(grid, convertedBack);
}
public static class TestEntity {
private Long id;
@ -794,6 +805,7 @@ public class DefaultConversionTests { @@ -794,6 +805,7 @@ public class DefaultConversionTests {
}
}
private static class ListWrapper {
private List<?> list;
@ -807,8 +819,10 @@ public class DefaultConversionTests { @@ -807,8 +819,10 @@ public class DefaultConversionTests {
}
}
public Object assignableTarget;
private static class SSN {
private String value;
@ -837,6 +851,7 @@ public class DefaultConversionTests { @@ -837,6 +851,7 @@ public class DefaultConversionTests {
}
}
private static class ISBN {
private String value;

Loading…
Cancel
Save