diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java index 9af68a7cfd..7533d39a7b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java @@ -1577,6 +1577,24 @@ public final class BeanWrapperTests { assertEquals(8, bwi.getPropertyValue("object")); } + @Test + public void testGenericArraySetter() { + SkipReaderStub foo = new SkipReaderStub(); + BeanWrapperImpl bwi = new BeanWrapperImpl(foo); + List values = new LinkedList(); + values.add("1"); + values.add("2"); + values.add("3"); + values.add("4"); + bwi.setPropertyValue("items", values); + Object[] result = foo.items; + assertEquals(4, result.length); + assertEquals("1", result[0]); + assertEquals("2", result[1]); + assertEquals("3", result[2]); + assertEquals("4", result[3]); + } + static class Spr10115Bean { @@ -1991,4 +2009,21 @@ public final class BeanWrapperTests { } } + + public static class SkipReaderStub { + + public T[] items; + + public SkipReaderStub() { + } + + public SkipReaderStub(T... items) { + this.items = items; + } + + public void setItems(T... items) { + this.items = items; + } + } + } diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index c89d7611d0..f7ac7daf66 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -628,7 +628,7 @@ public final class ResolvableType implements Serializable { * Resolve this type to a {@link java.lang.Class}, returning the specified * {@code fallback} if the type cannot be resolved. This method will consider bounds * of {@link TypeVariable}s and {@link WildcardType}s if direct resolution fails; - * however, bounds of Object.class will be ignored. + * however, bounds of {@code Object.class} will be ignored. * @param fallback the fallback class to use if resolution fails (may be {@code null}) * @return the resolved {@link Class} or the {@code fallback} * @see #resolve() 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 0036f81d22..95e94e9451 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 @@ -105,7 +105,7 @@ public class TypeDescriptor implements Serializable { public TypeDescriptor(Property property) { Assert.notNull(property, "Property must not be null"); this.resolvableType = ResolvableType.forMethodParameter(property.getMethodParameter()); - this.type = this.resolvableType.resolve(Object.class); + this.type = this.resolvableType.resolve(property.getType()); this.annotations = nullSafeAnnotations(property.getAnnotations()); }