From 41de5ad98388cdd206db5fe2fc48b7e79957b2d6 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 19 Jan 2024 18:22:22 +0100 Subject: [PATCH] Tread entities nested in arrays like PUT for merge patch requests. Fixes GH-2358. --- .../data/rest/webmvc/json/DomainObjectReader.java | 2 +- .../data/rest/webmvc/json/DomainObjectReaderUnitTests.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java index 5df73fbdd..81bfbcc70 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java @@ -402,7 +402,7 @@ private boolean handleArrayNode(ArrayNode array, Collection collection, if (ObjectNode.class.isInstance(jsonNode)) { nestedObjectFound = true; - doMerge((ObjectNode) jsonNode, next, mapper); + readPut((ObjectNode) jsonNode, next, mapper); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java index 2d588bf20..1129bbebe 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java @@ -237,8 +237,9 @@ void doesNotApplyInputToReadOnlyFields() throws Exception { assertThat(reader.readPut(node, sample, mapper).createdDate).isEqualTo(reference); } - @Test // DATAREST-931 - void readsPatchForEntityNestedInCollection() throws Exception { + @Test // DATAREST-931, GH-2358 + // https://datatracker.ietf.org/doc/html/rfc7386#section-2 + void handlesEntityNestedInAnArrayLikePutForPatchRequest() throws Exception { Phone phone = new Phone(); phone.creationDate = new GregorianCalendar(); @@ -251,7 +252,7 @@ void readsPatchForEntityNestedInCollection() throws Exception { User result = reader.read(source, user, new ObjectMapper()); - assertThat(result.phones.get(0).creationDate).isNotNull(); + assertThat(result.phones.get(0).creationDate).isNull(); } @Test // DATAREST-919