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 81b3670fe..63035da8c 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 @@ -169,7 +169,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 044103947..38aece334 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 @@ -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; + } }