Skip to content

Commit a1c538c

Browse files
committed
DATAREST-953 - Added test case to verify this is fixed.
Seems the change for DATAREST-938 has also fixed this one. Added a test case similar to what was provided in the example for the original ticket.
1 parent 69fcd39 commit a1c538c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void setUp() {
8181
mappingContext.getPersistentEntity(User.class);
8282
mappingContext.getPersistentEntity(Inner.class);
8383
mappingContext.getPersistentEntity(Outer.class);
84+
mappingContext.getPersistentEntity(Parent.class);
8485
mappingContext.afterPropertiesSet();
8586

8687
PersistentEntities entities = new PersistentEntities(Collections.singleton(mappingContext));
@@ -352,6 +353,26 @@ public void considersTransientProperties() throws Exception {
352353
assertThat(result.temporary, is("new temp"));
353354
}
354355

356+
/**
357+
* @see DATAREST-953
358+
*/
359+
@Test
360+
public void writesArrayForPut() throws Exception {
361+
362+
Child inner = new Child();
363+
inner.items = new ArrayList<Item>();
364+
inner.items.add(new Item());
365+
366+
Parent source = new Parent();
367+
source.inner = inner;
368+
369+
JsonNode node = new ObjectMapper().readTree("{ \"inner\" : { \"items\" : [ { \"some\" : \"value\" } ] } }");
370+
371+
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
372+
373+
assertThat(result.inner.items.get(0).some, is("value"));
374+
}
375+
355376
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
356377
static class TypeWithGenericMap {
357378

@@ -407,4 +428,19 @@ static class Inner {
407428
String name;
408429
String prop;
409430
}
431+
432+
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
433+
static class Parent {
434+
Child inner;
435+
}
436+
437+
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
438+
static class Child {
439+
List<Item> items;
440+
}
441+
442+
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
443+
static class Item {
444+
String some;
445+
}
410446
}

0 commit comments

Comments
 (0)