diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java index 763f9050ec7..48a759ce02b 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java @@ -295,12 +295,6 @@ public class GenericBinder implements Binder { "Unable to get model binding; cannot parse property expression from property string [" + property + "]", e); } - try { - propertyExpression.getValueType(createEvaluationContext()); - } catch (EvaluationException e) { - throw new IllegalArgumentException("Unable to get model binding; cannot access property '" - + propertyExpression.getExpressionString() + "'", e); - } return new BindingImpl(propertyExpression, configuration.getFormatter()); } @@ -694,7 +688,7 @@ public class GenericBinder implements Binder { builder.arg("label", new ResolvableArgument(property)); builder.arg("value", sourceValue); builder.defaultMessage("Successfully bound user value " + StylerUtils.style(sourceValue) - + "to property '" + property + "'"); + + " to property '" + property + "'"); return builder.build(); } }; diff --git a/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java b/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java index 2d99bd1f2f1..362ac9de5ce 100644 --- a/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java +++ b/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java @@ -264,7 +264,7 @@ public class GenericBinderTests { binder.registerFormatter(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter()); Map values = new LinkedHashMap(); values.put("addresses", "4655 Macy Lane:Melbourne:FL:35452,1234 Rostock Circle:Palm Bay:FL:32901,1977 Bel Aire Estates:Coker:AL:12345"); - binder.bind(values); + BindingResults results = binder.bind(values); Assert.assertEquals(3, bean.addresses.size()); assertEquals("4655 Macy Lane", bean.addresses.get(0).street); assertEquals("Melbourne", bean.addresses.get(0).city); diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java index 8ef76df56a9..16486c20f56 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java @@ -159,29 +159,69 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { + "request an interface or concrete implementation instead"); } return new ArrayToCollection(sourceType, targetType, this); - } - } - if (targetType.isArray()) { - if (sourceType.isCollection()) { - return new CollectionToArray(sourceType, targetType, this); + } else if (targetType.isMap()) { + if (sourceType.getElementType().equals(String.class)) { + // string array to map; with string element values in format foo=bar + return null; + } else { + return null; + } } else { + // array to object return null; } } if (sourceType.isCollection()) { - if (targetType.isCollection()) { + if (targetType.isCollection()) { return new CollectionToCollection(sourceType, targetType, this); + } else if (targetType.isArray()) { + return new CollectionToArray(sourceType, targetType, this); + } else if (targetType.isMap()) { + if (sourceType.getElementType().equals(String.class)) { + // string collection to map; with string element values in format foo=bar + return null; + } else { + return null; + } } else { + // collection to object return null; } } if (sourceType.isMap()) { if (targetType.isMap()) { return new MapToMap(sourceType, targetType, this); + } else if (targetType.isArray()) { + if (targetType.getElementType().equals(String.class)) { + // map to string array; with string element values in format foo=bar + return null; + } else { + return null; + } + } else if (targetType.isCollection()) { + if (targetType.getElementType().equals(String.class)) { + // map to string collection; with string element values in format foo=bar + return null; + } else { + return null; + } } else { + // map to object return null; } } + if (targetType.isArray()) { + // object to array + return null; + } + if (targetType.isCollection()) { + // object to collection + return null; + } + if (targetType.isMap()) { + // object to map + return null; + } if (sourceType.isAssignableTo(targetType)) { return NoOpConversionExecutor.INSTANCE; }