Merge branch '1.1.x'

pull/1332/merge
Dave Syer 10 years ago
commit 26cc628535

@ -69,7 +69,7 @@ if [ -z "${SPRING_HOME}" ]; then
done done
SAVED="`pwd`" SAVED="`pwd`"
cd "`dirname \"$PRG\"`/../" >&- cd "`dirname \"$PRG\"`/../" >&-
SPRING_HOME="`pwd -P`" export SPRING_HOME="`pwd -P`"
cd "$SAVED" >&- cd "$SAVED" >&-
fi fi

@ -28,6 +28,7 @@ import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.InvalidPropertyException; import org.springframework.beans.InvalidPropertyException;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue; import org.springframework.beans.PropertyValue;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.validation.DataBinder; import org.springframework.validation.DataBinder;
@ -47,6 +48,8 @@ public class RelaxedDataBinder extends DataBinder {
private boolean ignoreNestedProperties; private boolean ignoreNestedProperties;
private ConversionService relaxedConversionService;
/** /**
* Create a new {@link RelaxedDataBinder} instance. * Create a new {@link RelaxedDataBinder} instance.
* @param target the target into which properties are bound * @param target the target into which properties are bound
@ -76,12 +79,19 @@ public class RelaxedDataBinder extends DataBinder {
this.ignoreNestedProperties = ignoreNestedProperties; this.ignoreNestedProperties = ignoreNestedProperties;
} }
@Override
public void setConversionService(ConversionService conversionService) {
super.setConversionService(conversionService);
this.relaxedConversionService = new RelaxedConversionService(getConversionService());
}
@Override @Override
public void initBeanPropertyAccess() { public void initBeanPropertyAccess() {
super.initBeanPropertyAccess(); super.initBeanPropertyAccess();
this.relaxedConversionService = (this.relaxedConversionService != null
? this.relaxedConversionService : new RelaxedConversionService(getConversionService()));
// Hook in the RelaxedConversionService // Hook in the RelaxedConversionService
getInternalBindingResult().initConversion( getInternalBindingResult().initConversion(relaxedConversionService);
new RelaxedConversionService(getConversionService()));
} }
@Override @Override
@ -111,6 +121,7 @@ public class RelaxedDataBinder extends DataBinder {
} }
BeanWrapper targetWrapper = new BeanWrapperImpl(target); BeanWrapper targetWrapper = new BeanWrapperImpl(target);
targetWrapper.setConversionService(this.relaxedConversionService);
targetWrapper.setAutoGrowNestedPaths(true); targetWrapper.setAutoGrowNestedPaths(true);
List<PropertyValue> list = propertyValues.getPropertyValueList(); List<PropertyValue> list = propertyValues.getPropertyValueList();
@ -189,7 +200,6 @@ public class RelaxedDataBinder extends DataBinder {
TypeDescriptor descriptor = wrapper.getPropertyTypeDescriptor(name); TypeDescriptor descriptor = wrapper.getPropertyTypeDescriptor(name);
if (descriptor == null || descriptor.isMap()) { if (descriptor == null || descriptor.isMap()) {
if (descriptor != null) { if (descriptor != null) {
wrapper.getPropertyValue(name + "[foo]");
TypeDescriptor valueDescriptor = descriptor.getMapValueTypeDescriptor(); TypeDescriptor valueDescriptor = descriptor.getMapValueTypeDescriptor();
if (valueDescriptor != null) { if (valueDescriptor != null) {
Class<?> valueType = valueDescriptor.getObjectType(); Class<?> valueType = valueDescriptor.getObjectType();

@ -284,6 +284,15 @@ public class RelaxedDataBinderTests {
assertEquals("123", target.getNested().get("value.foo")); assertEquals("123", target.getNested().get("value.foo"));
} }
@Test
public void testBindNestedMapOfEnum() throws Exception {
this.conversionService = new DefaultConversionService();
TargetWithNestedMapOfEnum target = new TargetWithNestedMapOfEnum();
bind(target, "nested.this: bar\n" + "nested.ThAt: 123");
assertEquals("bar", target.getNested().get(Bingo.THIS));
assertEquals("123", target.getNested().get(Bingo.THAT));
}
@Test @Test
public void testBindNestedMapBracketReferenced() throws Exception { public void testBindNestedMapBracketReferenced() throws Exception {
TargetWithNestedMap target = new TargetWithNestedMap(); TargetWithNestedMap target = new TargetWithNestedMap();
@ -578,6 +587,19 @@ public class RelaxedDataBinderTests {
} }
public static class TargetWithNestedMapOfEnum {
private Map<Bingo, Object> nested;
public Map<Bingo, Object> getNested() {
return nested;
}
public void setNested(Map<Bingo, Object> nested) {
this.nested = nested;
}
}
public static class TargetWithNestedMapOfListOfString { public static class TargetWithNestedMapOfListOfString {
private Map<String, List<String>> nested; private Map<String, List<String>> nested;

Loading…
Cancel
Save