DATAREST-1249 - DomainObjectMerger now properly binds to uninitialized target collections.
This commit is contained in:
@@ -480,7 +480,9 @@ public class DomainObjectReader {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Collection<Object> asCollection(Object source) {
|
||||
|
||||
if (source instanceof Collection) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
} else if (source instanceof Collection) {
|
||||
return (Collection<Object>) source;
|
||||
} else if (source.getClass().isArray()) {
|
||||
return Arrays.asList(ObjectUtils.toObjectArray(source));
|
||||
|
||||
@@ -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));
|
||||
@@ -555,6 +556,17 @@ 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).containsExactly("value");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T as(Object source, Class<T> type) {
|
||||
|
||||
@@ -766,4 +778,11 @@ public class DomainObjectReaderUnitTests {
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
// DATAREST-1249
|
||||
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
static class WithNullCollection {
|
||||
List<String> strings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user