Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ protected Object evaluateValueFromTarget(Object targetObject, Class<?> entityTyp
}

protected final Object evaluate(Class<?> type) {
return value instanceof LateObjectEvaluator ? ((LateObjectEvaluator) value).evaluate(type) : value;
if (value instanceof LateObjectEvaluator) {
return ((LateObjectEvaluator) value).evaluate(type);
}
if (value.getClass() != type) {
throw new PatchException(String.format("Could not read %s into %s", value, type));
}
return value;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ void manipulatesNestedCollectionProperly() {
assertThat(outer.todoList.getTodos()).containsExactly(todos.get(0), todos.get(1), newTodo);
}


@Test
void failPrimitiveInNestedObjectCollection() {
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);

assertThatExceptionOfType(PatchException.class)
.isThrownBy(() -> AddOperation.of("/todos/-", "Primitive").perform(todoList, TodoList.class, TestPropertyPathContext.INSTANCE))
.withMessageContaining("Could not read")
.withMessageContaining("into class");
}

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class TodoListWrapper {
public TodoList todoList;

Expand Down