DATAREST-1479 - Patching collections now also works for nested collections.

We now properly use the PropertyPath's leaf property to check whether we need to deal with a collection in JSON Patch pointers.
This commit is contained in:
Oliver Drotbohm
2020-04-27 23:45:58 +02:00
parent 32aef5de7b
commit 399c846378
2 changed files with 29 additions and 1 deletions

View File

@@ -554,7 +554,7 @@ class SpelPath {
return nested(segment);
}
TypeInformation<?> typeInformation = basePath.getTypeInformation();
TypeInformation<?> typeInformation = basePath.getLeafProperty().getTypeInformation();
if (typeInformation.isMap()) {

View File

@@ -19,6 +19,10 @@ import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@@ -137,4 +141,28 @@ public class AddOperationUnitTests {
.withMessageContaining("2") //
.withMessageContaining("1");
}
@Test // DATAREST-1479
public void manipulatesNestedCollectionProperly() {
List<Todo> todos = new ArrayList<>();
todos.add(new Todo(1L, "A", false));
todos.add(new Todo(2L, "B", false));
TodoList todoList = new TodoList();
todoList.setTodos(todos);
TodoListWrapper outer = new TodoListWrapper(todoList);
Todo newTodo = new Todo(3L, "C", false);
AddOperation.of("/todoList/todos/-", newTodo).perform(outer, TodoListWrapper.class);
assertThat(outer.todoList.getTodos()).containsExactly(todos.get(0), todos.get(1), newTodo);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class TodoListWrapper {
public TodoList todoList;
}
}