Fixed regression with fallback for non-resolvable property type

master
Juergen Hoeller 11 years ago
parent 786e217991
commit 8570f607a7
  1. 35
      spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java
  2. 2
      spring-core/src/main/java/org/springframework/core/ResolvableType.java
  3. 2
      spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.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<String> values = new LinkedList<String>();
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<T> {
public T[] items;
public SkipReaderStub() {
}
public SkipReaderStub(T... items) {
this.items = items;
}
public void setItems(T... items) {
this.items = items;
}
}
}

@ -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()

@ -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());
}

Loading…
Cancel
Save