File tree Expand file tree Collapse file tree 4 files changed +47
-4
lines changed
spring-data-rest-webmvc/src
main/java/org/springframework/data/rest/webmvc/json/patch
test/java/org/springframework/data/rest/webmvc/json/patch Expand file tree Collapse file tree 4 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 2626 * Abstract base class representing and providing support methods for patch operations.
2727 *
2828 * @author Craig Walls
29+ * @author Mathias Düsterhöft
2930 */
3031public abstract class PatchOperation {
3132
@@ -164,7 +165,7 @@ protected Object getValueFromTarget(Object target) {
164165 * otherwise.
165166 */
166167 protected <T > Object evaluateValueFromTarget (Object targetObject , Class <T > entityType ) {
167- return value instanceof LateObjectEvaluator ? ((LateObjectEvaluator ) value ).evaluate (entityType ) : value ;
168+ return value instanceof LateObjectEvaluator ? ((LateObjectEvaluator ) value ).evaluate (spelExpression . getValueType ( targetObject ) ) : value ;
168169 }
169170
170171 /**
Original file line number Diff line number Diff line change 1515 */
1616package org .springframework .data .rest .webmvc .json .patch ;
1717
18- import static org .junit .Assert .*;
18+ import static org .junit .Assert .assertEquals ;
19+ import static org .junit .Assert .assertNotNull ;
20+ import static org .junit .Assert .assertTrue ;
1921
2022import java .util .ArrayList ;
2123import java .util .List ;
2224
2325import org .junit .Test ;
2426
27+ import com .fasterxml .jackson .databind .ObjectMapper ;
28+
2529public class ReplaceOperationTest {
2630
2731 @ Test
@@ -38,6 +42,20 @@ public void replaceBooleanPropertyValue() throws Exception {
3842 assertTrue (todos .get (1 ).isComplete ());
3943 }
4044
45+ @ Test
46+ public void replaceObjectPropertyValue () throws Exception {
47+ // initial Todo list
48+ Todo todo = new Todo (1L , "A" , false );
49+
50+ ReplaceOperation replace = new ReplaceOperation ("/type" , new JsonLateObjectEvaluator (new ObjectMapper ().readTree ("{\" value\" :\" new\" }" )));
51+ replace .perform (todo , Todo .class );
52+
53+ assertNotNull (todo .getType ());
54+ assertNotNull (todo .getType ().getValue ());
55+ assertTrue (todo .getType ().getValue ().equals ("new" ));
56+
57+ }
58+
4159 @ Test
4260 public void replaceTextPropertyValue () throws Exception {
4361 // initial Todo list
Original file line number Diff line number Diff line change 1616
1717package org .springframework .data .rest .webmvc .json .patch ;
1818
19- import lombok .AllArgsConstructor ;
2019import lombok .Data ;
2120import lombok .NoArgsConstructor ;
2221
2322/**
2423 * @author Roy Clarkson
2524 * @author Craig Walls
25+ * @author Mathias Düsterhöft
2626 */
2727@ Data
2828@ NoArgsConstructor
29- @ AllArgsConstructor
3029class Todo {
3130
3231 private Long id ;
3332 private String description ;
3433 private boolean complete ;
34+ private TodoType type = new TodoType ();
35+
36+ public Todo (Long id , String description , boolean complete ) {
37+ this .id = id ;
38+ this .description = description ;
39+ this .complete = complete ;
40+ }
3541}
Original file line number Diff line number Diff line change 1+ package org .springframework .data .rest .webmvc .json .patch ;
2+
3+ import javax .persistence .Embeddable ;
4+
5+ import lombok .AllArgsConstructor ;
6+ import lombok .Data ;
7+ import lombok .NoArgsConstructor ;
8+
9+ /**
10+ * @author Mathias Düsterhöft
11+ */
12+ @ Embeddable
13+ @ Data
14+ @ AllArgsConstructor
15+ @ NoArgsConstructor
16+ public class TodoType {
17+ private String value = "none" ;
18+ }
You can’t perform that action at this time.
0 commit comments