write method parameter type preferred over read method parameter type for property conversion (fixing regression; SPR-8964)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import test.beans.CustomEnum;
|
||||
import test.beans.GenericBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
@@ -109,4 +110,14 @@ public final class BeanWrapperEnumTests {
|
||||
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEnumSetWithGetterSetterMismatch() {
|
||||
GenericBean<?> gb = new GenericBean<Object>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("customEnumSetMismatch", new String[] {"VALUE_1", "VALUE_2"});
|
||||
assertEquals(2, gb.getCustomEnumSet().size());
|
||||
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1));
|
||||
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -21,6 +21,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -244,6 +245,17 @@ public class GenericBean<T> {
|
||||
this.customEnumSet = customEnumSet;
|
||||
}
|
||||
|
||||
public Set<CustomEnum> getCustomEnumSetMismatch() {
|
||||
return customEnumSet;
|
||||
}
|
||||
|
||||
public void setCustomEnumSetMismatch(Set<String> customEnumSet) {
|
||||
this.customEnumSet = new HashSet<CustomEnum>(customEnumSet.size());
|
||||
for (Iterator<String> iterator = customEnumSet.iterator(); iterator.hasNext(); ) {
|
||||
this.customEnumSet.add(CustomEnum.valueOf(iterator.next()));
|
||||
}
|
||||
}
|
||||
|
||||
public static GenericBean createInstance(Set<Integer> integerSet) {
|
||||
return new GenericBean(integerSet);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.convert;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
@@ -144,10 +145,7 @@ public final class Property {
|
||||
if (read == null && write == null) {
|
||||
throw new IllegalStateException("Property is neither readable nor writeable");
|
||||
}
|
||||
if (read != null && write != null && !write.getParameterType().isAssignableFrom(read.getParameterType())) {
|
||||
throw new IllegalStateException("Write parameter is not assignable from read parameter");
|
||||
}
|
||||
return read != null ? read : write;
|
||||
return (write != null ? write : read);
|
||||
}
|
||||
|
||||
private MethodParameter resolveReadMethodParameter() {
|
||||
|
||||
Reference in New Issue
Block a user