From c404e7936582848ac2bf3f26bd52310b48aea087 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 30 May 2018 10:48:26 +0200 Subject: [PATCH] DATAREST-1249 - Backport of tests. The issue doesn't seem to need a fix in this branch as DomainObjectReader already contains the guard we apparently had lost when moving to 3.0. --- .../json/DomainObjectReaderUnitTests.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 c5a2e0662..4d7425cff 100644 --- 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 @@ -112,6 +112,7 @@ public class DomainObjectReaderUnitTests { mappingContext.getPersistentEntity(CollectionOfEnumWithMethods.class); mappingContext.getPersistentEntity(SampleWithReference.class); mappingContext.getPersistentEntity(Note.class); + mappingContext.getPersistentEntity(WithNullCollection.class); mappingContext.afterPropertiesSet(); this.entities = new PersistentEntities(Collections.singleton(mappingContext)); @@ -554,6 +555,18 @@ public class DomainObjectReaderUnitTests { assertThat(result.tags, contains(second)); } + @Test // DATAREST-1249 + public void mergesIntoUninitializedCollection() throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + ObjectNode source = (ObjectNode) mapper.readTree("{ \"strings\" : [ \"value\" ] }"); + + WithNullCollection result = reader.readPut(source, new WithNullCollection(), mapper); + + assertThat(result.strings, hasSize(1)); + assertThat(result.strings, hasItem("value")); + } + @SuppressWarnings("unchecked") private static T as(Object source, Class type) { @@ -768,4 +781,11 @@ public class DomainObjectReaderUnitTests { return null; } } + + // DATAREST-1249 + + @JsonAutoDetect(fieldVisibility = Visibility.ANY) + static class WithNullCollection { + List strings; + } }