From b9bac1d3b6cba90997b4c2564bcff3d8d51ab19b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 26 Mar 2014 16:09:15 +0100 Subject: [PATCH] Relaxed getElementTypeDescriptor assertion to not insist on a ResolvableType-known array Issue: SPR-11608 --- .../core/convert/TypeDescriptor.java | 2 -- .../support/DefaultConversionTests.java | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 8b658eede4..02f07be0be 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -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()); - } /** diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java index 8f98b475d2..a832022a78 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java @@ -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.*; */ 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 { 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 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 { } } + private static class ListWrapper { private List list; @@ -807,8 +819,10 @@ public class DefaultConversionTests { } } + public Object assignableTarget; + private static class SSN { private String value; @@ -837,6 +851,7 @@ public class DefaultConversionTests { } } + private static class ISBN { private String value;