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; + } }