DATAREST-938 - Update nested entities instead of replacing them with new instances.
Original pull request: #241.
This commit is contained in:
committed by
Oliver Gierke
parent
a4f88fe1ac
commit
b859b8b91f
@@ -209,6 +209,7 @@ public class DomainObjectReader {
|
||||
}
|
||||
|
||||
if (rawValue != null && property.isEntity()) {
|
||||
i.remove();
|
||||
doMerge(objectNode, rawValue, mapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ public class DomainObjectReaderUnitTests {
|
||||
mappingContext.getPersistentEntity(SampleWithCreatedDate.class);
|
||||
mappingContext.getPersistentEntity(SampleWithTransient.class);
|
||||
mappingContext.getPersistentEntity(User.class);
|
||||
mappingContext.getPersistentEntity(Inner.class);
|
||||
mappingContext.getPersistentEntity(Outer.class);
|
||||
mappingContext.afterPropertiesSet();
|
||||
|
||||
PersistentEntities entities = new PersistentEntities(Collections.singleton(mappingContext));
|
||||
@@ -272,6 +274,31 @@ public class DomainObjectReaderUnitTests {
|
||||
assertThat(sub4.get("c2"), is("new"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-938
|
||||
*/
|
||||
@Test
|
||||
public void nestedEntitiesAreUpdated() throws Exception {
|
||||
|
||||
Inner inner = new Inner();
|
||||
inner.name = "inner name";
|
||||
inner.prop = "something";
|
||||
Outer outer = new Outer();
|
||||
outer.prop = "else";
|
||||
outer.name = "outer name";
|
||||
outer.inner = inner;
|
||||
|
||||
JsonNode node = new ObjectMapper().readTree("{ \"inner\" : { \"name\" : \"new inner name\" } }");
|
||||
|
||||
Outer result = reader.merge((ObjectNode) node, outer, new ObjectMapper());
|
||||
|
||||
assertThat(result, is(sameInstance(outer)));
|
||||
assertThat(result.prop, is("else"));
|
||||
assertThat(result.inner.prop, is("something"));
|
||||
assertThat(result.inner.name, is("new inner name"));
|
||||
assertThat(result.inner, is(sameInstance(inner)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T as(Object source, Class<T> type) {
|
||||
|
||||
@@ -364,4 +391,19 @@ public class DomainObjectReaderUnitTests {
|
||||
String name;
|
||||
@Transient String temporary;
|
||||
}
|
||||
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
static class Outer {
|
||||
|
||||
String name;
|
||||
String prop;
|
||||
Inner inner;
|
||||
}
|
||||
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
static class Inner {
|
||||
|
||||
String name;
|
||||
String prop;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user