diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java index d04ab68aa..1d51128d3 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java @@ -181,7 +181,6 @@ public class DomainObjectReader { String fieldName = entry.getKey(); if (!mappedProperties.hasPersistentPropertyForField(fieldName)) { - i.remove(); continue; } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java index 6721ffad9..2479f3535 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java @@ -37,6 +37,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.mapping.context.PersistentEntities; import org.springframework.data.mongodb.core.mapping.MongoMappingContext; @@ -72,6 +73,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(); @@ -80,6 +82,23 @@ public class DomainObjectReaderUnitTests { this.reader = new DomainObjectReader(entities, mappings); } + /** + * @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 */ @@ -333,4 +352,11 @@ public class DomainObjectReaderUnitTests { public Calendar creationDate; public String label; } + + @JsonAutoDetect(fieldVisibility = Visibility.ANY) + static class SampleWithTransient { + + String name; + @Transient String temporary; + } }