Skip to content

Commit

Permalink
DATACMNS-1282 - Switched to SimpleEvaluationContext in MapDataBinder.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Mar 27, 2018
1 parent b0dc8be commit ae1dd27
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/main/java/org/springframework/data/web/MapDataBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ae1dd27

Please sign in to comment.