Permalink
Browse files

DATACMNS-1282 - Switched to SimpleEvaluationContext in MapDataBinder.

  • Loading branch information...
odrotbohm committed Mar 27, 2018
1 parent b0dc8be commit ae1dd2741ce06d44a0966ecbd6f47beabde2b653
Showing with 9 additions and 13 deletions.
  1. +9 −13 src/main/java/org/springframework/data/web/MapDataBinder.java
@@ -44,11 +44,9 @@
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 @@ public void setPropertyValue(String propertyName, @Nullable Object value) throws
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 @@ public void setPropertyValue(String propertyName, @Nullable Object value) throws
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) {

0 comments on commit ae1dd27

Please sign in to comment.