DATAREST-959 - Fix adding elements to empty array in DomainObjectReader.

Original pull request: #246.
This commit is contained in:
Milos Cubrilo
2016-12-12 18:46:28 +01:00
committed by Oliver Gierke
parent 83899bb42a
commit 0b1bbbab31
2 changed files with 19 additions and 1 deletions

View File

@@ -348,7 +348,7 @@ public class DomainObjectReader {
private static Collection<Object> asCollection(Object source) {
if (source == null) {
return Collections.emptyList();
return new ArrayList<Object>();
}
if (source instanceof Collection) {

View File

@@ -390,6 +390,24 @@ public class DomainObjectReaderUnitTests {
assertThat(result.inner.items.get(0).some, is("value"));
}
/**
* @see DATAREST-959
*/
@Test
public void writesArrayOverUndefinedValueForPut() throws Exception {
Parent source = new Parent();
source.inner = new Child();
source.inner.items = null;
JsonNode node = new ObjectMapper().readTree("{ \"inner\" : { \"items\" : [ { \"some\" : \"value\" } ] } }");
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
assertThat(result.inner.items.size(), is(1));
assertThat(result.inner.items.get(0).some, is("value"));
}
@Test
public void testname() throws Exception {