Skip to content

Commit

Permalink
DATAREST-937 - Transient properties in JSON are now included in merge.
Browse files Browse the repository at this point in the history
We now don't prematurely drop fields that don't have a persistent property exposed in DomainObjectReader. Doing so dropped values for transient fields as the latter are not exposed as persistent property in the first place. We still skip any nested merging though.

Original pull request: #240.
  • Loading branch information
candrews authored and odrotbohm committed Dec 6, 2016
1 parent 603db86 commit 4150688
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ private <T> T doMerge(ObjectNode root, T target, ObjectMapper mapper) throws Exc
String fieldName = entry.getKey();

if (!mappedProperties.hasPersistentPropertyForField(fieldName)) {
i.remove();
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.annotation.Transient;
import org.springframework.data.annotation.Version;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
import org.springframework.data.mapping.context.PersistentEntities;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void setUp() {
mappingContext.getPersistentEntity(TypeWithGenericMap.class);
mappingContext.getPersistentEntity(VersionedType.class);
mappingContext.getPersistentEntity(SampleWithCreatedDate.class);
mappingContext.getPersistentEntity(SampleWithTransient.class);
mappingContext.getPersistentEntity(User.class);
mappingContext.afterPropertiesSet();

Expand All @@ -83,6 +85,23 @@ public void setUp() {
this.reader = new DomainObjectReader(entities, new Associations(mappings, mock(RepositoryRestConfiguration.class)));
}

/**
* @see DATAREST-
*/
@Test
public void considersTransientProperties() throws Exception {

SampleWithTransient sample = new SampleWithTransient();
sample.name="name";
sample.temporary="temp";
JsonNode node = new ObjectMapper().readTree("{\"name\": \"new name\", \"temporary\": \"new temp\"}");

SampleWithTransient result = reader.readPut((ObjectNode) node, sample, new ObjectMapper());

assertThat(result.name, is("new name"));
assertThat(result.temporary, is("new temp"));
}

/**
* @see DATAREST-461
*/
Expand Down Expand Up @@ -336,4 +355,11 @@ static class Phone {
public Calendar creationDate;
public String label;
}

@JsonAutoDetect(fieldVisibility = Visibility.ANY)
static class SampleWithTransient {

String name;
@Transient String temporary;
}
}

0 comments on commit 4150688

Please sign in to comment.