|
44 | 44 | import org.springframework.expression.Expression;
|
45 | 45 | import org.springframework.expression.TypedValue;
|
46 | 46 | import org.springframework.expression.spel.SpelEvaluationException;
|
47 |
| -import org.springframework.expression.spel.SpelMessage; |
48 | 47 | import org.springframework.expression.spel.SpelParserConfiguration;
|
49 | 48 | 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; |
52 | 50 | import org.springframework.lang.Nullable;
|
53 | 51 | import org.springframework.util.Assert;
|
54 | 52 | import org.springframework.web.bind.WebDataBinder;
|
@@ -176,16 +174,6 @@ public void setPropertyValue(String propertyName, @Nullable Object value) throws
|
176 | 174 | throw new NotWritablePropertyException(type, propertyName);
|
177 | 175 | }
|
178 | 176 |
|
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 |
| - |
189 | 177 | PropertyPath leafProperty = getPropertyPath(propertyName).getLeafProperty();
|
190 | 178 | TypeInformation<?> owningType = leafProperty.getOwningType();
|
191 | 179 | TypeInformation<?> propertyType = leafProperty.getTypeInformation();
|
@@ -213,6 +201,14 @@ public void setPropertyValue(String propertyName, @Nullable Object value) throws
|
213 | 201 | value = conversionService.convert(value, TypeDescriptor.forObject(value), typeDescriptor);
|
214 | 202 | }
|
215 | 203 |
|
| 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 | + |
216 | 212 | try {
|
217 | 213 | expression.setValue(context, value);
|
218 | 214 | } catch (SpelEvaluationException o_O) {
|
|
0 commit comments