Skip to content

Commit cba8b3b

Browse files
committed
DATAREST-1222 - Switched to SimpleEvaluationContext for SpEL-based PATCH handling.
1 parent dfd7f11 commit cba8b3b

File tree

1 file changed

+7
-4
lines changed
  • spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch

1 file changed

+7
-4
lines changed

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
import org.springframework.core.convert.TypeDescriptor;
3333
import org.springframework.data.mapping.PropertyPath;
3434
import org.springframework.data.mapping.PropertyReferenceException;
35+
import org.springframework.expression.EvaluationContext;
3536
import org.springframework.expression.Expression;
3637
import org.springframework.expression.ExpressionException;
3738
import org.springframework.expression.spel.SpelEvaluationException;
3839
import org.springframework.expression.spel.standard.SpelExpressionParser;
40+
import org.springframework.expression.spel.support.SimpleEvaluationContext;
3941
import org.springframework.util.Assert;
4042
import org.springframework.util.ConcurrentReferenceHashMap;
4143

@@ -209,6 +211,7 @@ static class TypedSpelPath extends SpelPath {
209211

210212
private static final String INVALID_PATH_REFERENCE = "Invalid path reference %s on type %s (from source %s)!";
211213
private static final Map<CacheKey, TypedSpelPath> TYPED_PATHS = new ConcurrentReferenceHashMap<>(32);
214+
private static final EvaluationContext CONTEXT = SimpleEvaluationContext.forReadWriteDataBinding().build();
212215

213216
private final Class<?> type;
214217

@@ -254,7 +257,7 @@ public <T> T getValue(Object target) {
254257
Assert.notNull(target, "Target must not be null!");
255258

256259
try {
257-
return (T) expression.getValue(target);
260+
return (T) expression.getValue(CONTEXT, target);
258261
} catch (ExpressionException o_O) {
259262
throw new PatchException("Unable to get value from target", o_O);
260263
}
@@ -270,7 +273,7 @@ public void setValue(Object target, Object value) {
270273

271274
Assert.notNull(target, "Target must not be null!");
272275

273-
expression.setValue(target, value);
276+
expression.setValue(CONTEXT, target, value);
274277
}
275278

276279
/**
@@ -283,7 +286,7 @@ public Class<?> getType(Object root) {
283286

284287
Assert.notNull(root, "Root object must not be null!");
285288

286-
return expression.getValueType(root);
289+
return expression.getValueType(CONTEXT, root);
287290
}
288291

289292
/**
@@ -390,7 +393,7 @@ private TypedSpelPath getParent() {
390393
}
391394

392395
private TypeDescriptor getTypeDescriptor(Object target) {
393-
return expression.getValueTypeDescriptor(target);
396+
return expression.getValueTypeDescriptor(CONTEXT, target);
394397
}
395398

396399
private Integer getTargetListIndex() {

0 commit comments

Comments
 (0)