From ae1dd2741ce06d44a0966ecbd6f47beabde2b653 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 | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/springframework/data/web/MapDataBinder.java b/src/main/java/org/springframework/data/web/MapDataBinder.java index 045254a14..3c9af9321 100644 --- a/src/main/java/org/springframework/data/web/MapDataBinder.java +++ b/src/main/java/org/springframework/data/web/MapDataBinder.java @@ -44,11 +44,9 @@ import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; 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.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.WebDataBinder; @@ -176,16 +174,6 @@ class MapDataBinder extends WebDataBinder { throw new NotWritablePropertyException(type, propertyName); } - StandardEvaluationContext context = new StandardEvaluationContext(); - context.addPropertyAccessor(new PropertyTraversingMapAccessor(type, conversionService)); - context.setTypeConverter(new StandardTypeConverter(conversionService)); - context.setTypeLocator(typeName -> { - throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName); - }); - context.setRootObject(map); - - Expression expression = PARSER.parseExpression(propertyName); - PropertyPath leafProperty = getPropertyPath(propertyName).getLeafProperty(); TypeInformation owningType = leafProperty.getOwningType(); TypeInformation propertyType = leafProperty.getTypeInformation(); @@ -213,6 +201,14 @@ class MapDataBinder extends WebDataBinder { 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) {