Skip to content

Commit ae1dd27

Browse files
committed
DATACMNS-1282 - Switched to SimpleEvaluationContext in MapDataBinder.
1 parent b0dc8be commit ae1dd27

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

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

+9-13
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@
4444
import org.springframework.expression.Expression;
4545
import org.springframework.expression.TypedValue;
4646
import org.springframework.expression.spel.SpelEvaluationException;
47-
import org.springframework.expression.spel.SpelMessage;
4847
import org.springframework.expression.spel.SpelParserConfiguration;
4948
import org.springframework.expression.spel.standard.SpelExpressionParser;
50-
import org.springframework.expression.spel.support.StandardEvaluationContext;
51-
import org.springframework.expression.spel.support.StandardTypeConverter;
49+
import org.springframework.expression.spel.support.SimpleEvaluationContext;
5250
import org.springframework.lang.Nullable;
5351
import org.springframework.util.Assert;
5452
import org.springframework.web.bind.WebDataBinder;
@@ -176,16 +174,6 @@ public void setPropertyValue(String propertyName, @Nullable Object value) throws
176174
throw new NotWritablePropertyException(type, propertyName);
177175
}
178176

179-
StandardEvaluationContext context = new StandardEvaluationContext();
180-
context.addPropertyAccessor(new PropertyTraversingMapAccessor(type, conversionService));
181-
context.setTypeConverter(new StandardTypeConverter(conversionService));
182-
context.setTypeLocator(typeName -> {
183-
throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName);
184-
});
185-
context.setRootObject(map);
186-
187-
Expression expression = PARSER.parseExpression(propertyName);
188-
189177
PropertyPath leafProperty = getPropertyPath(propertyName).getLeafProperty();
190178
TypeInformation<?> owningType = leafProperty.getOwningType();
191179
TypeInformation<?> propertyType = leafProperty.getTypeInformation();
@@ -213,6 +201,14 @@ public void setPropertyValue(String propertyName, @Nullable Object value) throws
213201
value = conversionService.convert(value, TypeDescriptor.forObject(value), typeDescriptor);
214202
}
215203

204+
EvaluationContext context = SimpleEvaluationContext //
205+
.forPropertyAccessors(new PropertyTraversingMapAccessor(type, conversionService)) //
206+
.withConversionService(conversionService) //
207+
.withRootObject(map) //
208+
.build();
209+
210+
Expression expression = PARSER.parseExpression(propertyName);
211+
216212
try {
217213
expression.setValue(context, value);
218214
} catch (SpelEvaluationException o_O) {

0 commit comments

Comments
 (0)