From b1a20ae1e82a63f99b3afc6f2aaedb3bf4dc432a Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 27 Mar 2018 16:21:58 +0200 Subject: [PATCH] DATACMNS-1282 - Switched to SimpleEvaluationContext in MapDataBinder. --- .../data/web/MapDataBinder.java | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/springframework/data/web/MapDataBinder.java b/src/main/java/org/springframework/data/web/MapDataBinder.java index fc9d165f28..cf7db6a2ba 100644 --- a/src/main/java/org/springframework/data/web/MapDataBinder.java +++ b/src/main/java/org/springframework/data/web/MapDataBinder.java @@ -39,16 +39,12 @@ import org.springframework.data.util.TypeInformation; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; -import org.springframework.expression.EvaluationException; import org.springframework.expression.Expression; -import org.springframework.expression.TypeLocator; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.SpelEvaluationException; -import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.SpelParserConfiguration; import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.expression.spel.support.StandardTypeConverter; +import org.springframework.expression.spel.support.SimpleEvaluationContext; import org.springframework.util.Assert; import org.springframework.web.bind.WebDataBinder; @@ -108,13 +104,6 @@ private static class MapPropertyAccessor extends AbstractPropertyAccessor { private static final SpelExpressionParser PARSER = new SpelExpressionParser( new SpelParserConfiguration(false, true)); - private static final TypeLocator REJECTING_LOCATOR = new TypeLocator() { - - @Override - public Class findType(String typeName) throws EvaluationException { - throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName); - } - }; private final @NonNull Class type; private final @NonNull Map map; @@ -172,14 +161,6 @@ public void setPropertyValue(String propertyName, Object value) throws BeansExce throw new NotWritablePropertyException(type, propertyName); } - StandardEvaluationContext context = new StandardEvaluationContext(); - context.addPropertyAccessor(new PropertyTraversingMapAccessor(type, conversionService)); - context.setTypeConverter(new StandardTypeConverter(conversionService)); - context.setTypeLocator(REJECTING_LOCATOR); - context.setRootObject(map); - - Expression expression = PARSER.parseExpression(propertyName); - PropertyPath leafProperty = getPropertyPath(propertyName).getLeafProperty(); TypeInformation owningType = leafProperty.getOwningType(); TypeInformation propertyType = owningType.getProperty(leafProperty.getSegment()); @@ -196,6 +177,15 @@ public void setPropertyValue(String propertyName, Object value) throws BeansExce value = conversionService.convert(value, TypeDescriptor.forObject(value), typeDescriptor); } + EvaluationContext context = SimpleEvaluationContext // + + .forPropertyAccessors(new PropertyTraversingMapAccessor(type, conversionService)) // + .withConversionService(conversionService) // + .withRootObject(map) // + .build(); + + Expression expression = PARSER.parseExpression(propertyName); + try { expression.setValue(context, value); } catch (SpelEvaluationException o_O) {