Skip to content

Commit b1a20ae

Browse files
committed
DATACMNS-1282 - Switched to SimpleEvaluationContext in MapDataBinder.
1 parent 4715675 commit b1a20ae

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/main/java/org/springframework/data/web/MapDataBinder.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@
3939
import org.springframework.data.util.TypeInformation;
4040
import org.springframework.expression.AccessException;
4141
import org.springframework.expression.EvaluationContext;
42-
import org.springframework.expression.EvaluationException;
4342
import org.springframework.expression.Expression;
44-
import org.springframework.expression.TypeLocator;
4543
import org.springframework.expression.TypedValue;
4644
import org.springframework.expression.spel.SpelEvaluationException;
47-
import org.springframework.expression.spel.SpelMessage;
4845
import org.springframework.expression.spel.SpelParserConfiguration;
4946
import org.springframework.expression.spel.standard.SpelExpressionParser;
50-
import org.springframework.expression.spel.support.StandardEvaluationContext;
51-
import org.springframework.expression.spel.support.StandardTypeConverter;
47+
import org.springframework.expression.spel.support.SimpleEvaluationContext;
5248
import org.springframework.util.Assert;
5349
import org.springframework.web.bind.WebDataBinder;
5450

@@ -108,13 +104,6 @@ private static class MapPropertyAccessor extends AbstractPropertyAccessor {
108104

109105
private static final SpelExpressionParser PARSER = new SpelExpressionParser(
110106
new SpelParserConfiguration(false, true));
111-
private static final TypeLocator REJECTING_LOCATOR = new TypeLocator() {
112-
113-
@Override
114-
public Class<?> findType(String typeName) throws EvaluationException {
115-
throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName);
116-
}
117-
};
118107

119108
private final @NonNull Class<?> type;
120109
private final @NonNull Map<String, Object> map;
@@ -172,14 +161,6 @@ public void setPropertyValue(String propertyName, Object value) throws BeansExce
172161
throw new NotWritablePropertyException(type, propertyName);
173162
}
174163

175-
StandardEvaluationContext context = new StandardEvaluationContext();
176-
context.addPropertyAccessor(new PropertyTraversingMapAccessor(type, conversionService));
177-
context.setTypeConverter(new StandardTypeConverter(conversionService));
178-
context.setTypeLocator(REJECTING_LOCATOR);
179-
context.setRootObject(map);
180-
181-
Expression expression = PARSER.parseExpression(propertyName);
182-
183164
PropertyPath leafProperty = getPropertyPath(propertyName).getLeafProperty();
184165
TypeInformation<?> owningType = leafProperty.getOwningType();
185166
TypeInformation<?> propertyType = owningType.getProperty(leafProperty.getSegment());
@@ -196,6 +177,15 @@ public void setPropertyValue(String propertyName, Object value) throws BeansExce
196177
value = conversionService.convert(value, TypeDescriptor.forObject(value), typeDescriptor);
197178
}
198179

180+
EvaluationContext context = SimpleEvaluationContext //
181+
182+
.forPropertyAccessors(new PropertyTraversingMapAccessor(type, conversionService)) //
183+
.withConversionService(conversionService) //
184+
.withRootObject(map) //
185+
.build();
186+
187+
Expression expression = PARSER.parseExpression(propertyName);
188+
199189
try {
200190
expression.setValue(context, value);
201191
} catch (SpelEvaluationException o_O) {

0 commit comments

Comments
 (0)