DATAREST-937 - Transient properties in JSON are now included in merge.
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.
This commit is contained in:
committed by
Oliver Gierke
parent
7b5167ba09
commit
17fbdbb8a2
@@ -169,7 +169,6 @@ public class DomainObjectReader {
|
||||
String fieldName = entry.getKey();
|
||||
|
||||
if (!mappedProperties.hasPersistentPropertyForField(fieldName)) {
|
||||
i.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
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;
|
||||
@@ -75,6 +76,7 @@ public class DomainObjectReaderUnitTests {
|
||||
mappingContext.getPersistentEntity(TypeWithGenericMap.class);
|
||||
mappingContext.getPersistentEntity(VersionedType.class);
|
||||
mappingContext.getPersistentEntity(SampleWithCreatedDate.class);
|
||||
mappingContext.getPersistentEntity(SampleWithTransient.class);
|
||||
mappingContext.getPersistentEntity(User.class);
|
||||
mappingContext.afterPropertiesSet();
|
||||
|
||||
@@ -83,6 +85,23 @@ public class DomainObjectReaderUnitTests {
|
||||
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
|
||||
*/
|
||||
@@ -336,4 +355,11 @@ public class DomainObjectReaderUnitTests {
|
||||
public Calendar creationDate;
|
||||
public String label;
|
||||
}
|
||||
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
static class SampleWithTransient {
|
||||
|
||||
String name;
|
||||
@Transient String temporary;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user