Skip to content

Commit 41de5ad

Browse files
committed
Tread entities nested in arrays like PUT for merge patch requests.
Fixes GH-2358.
1 parent 6cec482 commit 41de5ad

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private boolean handleArrayNode(ArrayNode array, Collection<Object> collection,
402402
if (ObjectNode.class.isInstance(jsonNode)) {
403403

404404
nestedObjectFound = true;
405-
doMerge((ObjectNode) jsonNode, next, mapper);
405+
readPut((ObjectNode) jsonNode, next, mapper);
406406
}
407407
}
408408

Diff for: spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ void doesNotApplyInputToReadOnlyFields() throws Exception {
237237
assertThat(reader.readPut(node, sample, mapper).createdDate).isEqualTo(reference);
238238
}
239239

240-
@Test // DATAREST-931
241-
void readsPatchForEntityNestedInCollection() throws Exception {
240+
@Test // DATAREST-931, GH-2358
241+
// https://datatracker.ietf.org/doc/html/rfc7386#section-2
242+
void handlesEntityNestedInAnArrayLikePutForPatchRequest() throws Exception {
242243

243244
Phone phone = new Phone();
244245
phone.creationDate = new GregorianCalendar();
@@ -251,7 +252,7 @@ void readsPatchForEntityNestedInCollection() throws Exception {
251252

252253
User result = reader.read(source, user, new ObjectMapper());
253254

254-
assertThat(result.phones.get(0).creationDate).isNotNull();
255+
assertThat(result.phones.get(0).creationDate).isNull();
255256
}
256257

257258
@Test // DATAREST-919

0 commit comments

Comments
 (0)