Skip to content

Commit b9bac1d

Browse files
committed
Relaxed getElementTypeDescriptor assertion to not insist on a ResolvableType-known array
Issue: SPR-11608
1 parent 3388573 commit b9bac1d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,7 @@ public TypeDescriptor getElementTypeDescriptor() {
325325
if (this.resolvableType.isArray()) {
326326
return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations);
327327
}
328-
Assert.state(isCollection(), "Not an array or java.util.Collection");
329328
return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric());
330-
331329
}
332330

333331
/**

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,7 +53,8 @@
5353
*/
5454
public class DefaultConversionTests {
5555

56-
private DefaultConversionService conversionService = new DefaultConversionService();
56+
private final DefaultConversionService conversionService = new DefaultConversionService();
57+
5758

5859
@Test
5960
public void testStringToCharacter() {
@@ -777,6 +778,16 @@ public char[] convert(String source) {
777778
assertThat(converted, equalTo(new char[] { 'a', 'b', 'c' }));
778779
}
779780

781+
@Test
782+
public void multidimensionalArrayToListConversionShouldConvertEntriesCorrectly() {
783+
String[][] grid = new String[][] { new String[] { "1", "2", "3", "4" }, new String[] { "5", "6", "7", "8" },
784+
new String[] { "9", "10", "11", "12" } };
785+
List<String[]> converted = conversionService.convert(grid, List.class);
786+
String[][] convertedBack = conversionService.convert(converted, String[][].class);
787+
assertArrayEquals(grid, convertedBack);
788+
}
789+
790+
780791
public static class TestEntity {
781792

782793
private Long id;
@@ -794,6 +805,7 @@ public static TestEntity findTestEntity(Long id) {
794805
}
795806
}
796807

808+
797809
private static class ListWrapper {
798810

799811
private List<?> list;
@@ -807,8 +819,10 @@ public List<?> getList() {
807819
}
808820
}
809821

822+
810823
public Object assignableTarget;
811824

825+
812826
private static class SSN {
813827

814828
private String value;
@@ -837,6 +851,7 @@ public String toString() {
837851
}
838852
}
839853

854+
840855
private static class ISBN {
841856

842857
private String value;

0 commit comments

Comments
 (0)