From 7eaf50d997e2f1ee799c7c4642964d5f19a4695e Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 28 Mar 2018 09:43:29 +0200 Subject: [PATCH] DATAREST-1222 - Switched to SimpleEvaluationContext for SpEL-based PATCH handling. --- .../data/rest/webmvc/json/patch/SpelPath.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java index e3be1c275..469300bce 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java @@ -32,10 +32,12 @@ import org.springframework.core.CollectionFactory; import org.springframework.core.convert.TypeDescriptor; import org.springframework.data.mapping.PropertyPath; import org.springframework.data.mapping.PropertyReferenceException; +import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.expression.ExpressionException; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.SimpleEvaluationContext; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; @@ -209,6 +211,7 @@ class SpelPath { private static final String INVALID_PATH_REFERENCE = "Invalid path reference %s on type %s (from source %s)!"; private static final Map TYPED_PATHS = new ConcurrentReferenceHashMap<>(32); + private static final EvaluationContext CONTEXT = SimpleEvaluationContext.forReadWriteDataBinding().build(); private final Class type; @@ -254,7 +257,7 @@ class SpelPath { Assert.notNull(target, "Target must not be null!"); try { - return (T) expression.getValue(target); + return (T) expression.getValue(CONTEXT, target); } catch (ExpressionException o_O) { throw new PatchException("Unable to get value from target", o_O); } @@ -270,7 +273,7 @@ class SpelPath { Assert.notNull(target, "Target must not be null!"); - expression.setValue(target, value); + expression.setValue(CONTEXT, target, value); } /** @@ -283,7 +286,7 @@ class SpelPath { Assert.notNull(root, "Root object must not be null!"); - return expression.getValueType(root); + return expression.getValueType(CONTEXT, root); } /** @@ -390,7 +393,7 @@ class SpelPath { } private TypeDescriptor getTypeDescriptor(Object target) { - return expression.getValueTypeDescriptor(target); + return expression.getValueTypeDescriptor(CONTEXT, target); } private Integer getTargetListIndex() {