39
39
import org .springframework .data .util .TypeInformation ;
40
40
import org .springframework .expression .AccessException ;
41
41
import org .springframework .expression .EvaluationContext ;
42
- import org .springframework .expression .EvaluationException ;
43
42
import org .springframework .expression .Expression ;
44
- import org .springframework .expression .TypeLocator ;
45
43
import org .springframework .expression .TypedValue ;
46
44
import org .springframework .expression .spel .SpelEvaluationException ;
47
- import org .springframework .expression .spel .SpelMessage ;
48
45
import org .springframework .expression .spel .SpelParserConfiguration ;
49
46
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 ;
52
48
import org .springframework .util .Assert ;
53
49
import org .springframework .web .bind .WebDataBinder ;
54
50
@@ -108,13 +104,6 @@ private static class MapPropertyAccessor extends AbstractPropertyAccessor {
108
104
109
105
private static final SpelExpressionParser PARSER = new SpelExpressionParser (
110
106
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
- };
118
107
119
108
private final @ NonNull Class <?> type ;
120
109
private final @ NonNull Map <String , Object > map ;
@@ -172,14 +161,6 @@ public void setPropertyValue(String propertyName, Object value) throws BeansExce
172
161
throw new NotWritablePropertyException (type , propertyName );
173
162
}
174
163
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
-
183
164
PropertyPath leafProperty = getPropertyPath (propertyName ).getLeafProperty ();
184
165
TypeInformation <?> owningType = leafProperty .getOwningType ();
185
166
TypeInformation <?> propertyType = owningType .getProperty (leafProperty .getSegment ());
@@ -196,6 +177,15 @@ public void setPropertyValue(String propertyName, Object value) throws BeansExce
196
177
value = conversionService .convert (value , TypeDescriptor .forObject (value ), typeDescriptor );
197
178
}
198
179
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
+
199
189
try {
200
190
expression .setValue (context , value );
201
191
} catch (SpelEvaluationException o_O ) {
0 commit comments