diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/MappedProperties.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/MappedProperties.java index 3492eb38d..dc6d7094b 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/MappedProperties.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/MappedProperties.java @@ -38,6 +38,7 @@ import com.fasterxml.jackson.databind.introspect.ClassIntrospector; * * @author Oliver Gierke * @author Mark Paluch + * @author Mathias Düsterhöft */ class MappedProperties { @@ -64,6 +65,10 @@ class MappedProperties { for (BeanPropertyDefinition property : description.findProperties()) { + if (description.getIgnoredPropertyNames().contains(property.getName())) { + continue; + } + PersistentProperty persistentProperty = entity.getPersistentProperty(property.getInternalName()); if (persistentProperty != null) { 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 5eeb8633a..c5a2e0662 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 @@ -15,6 +15,7 @@ */ package org.springframework.data.rest.webmvc.json; +import static com.fasterxml.jackson.annotation.JsonProperty.Access.READ_ONLY; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -64,6 +65,7 @@ import org.springframework.data.rest.webmvc.mapping.Associations; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; @@ -206,6 +208,22 @@ public class DomainObjectReaderUnitTests { assertThat(result.version, is(1L)); } + @Test //DATAREST-1006 + public void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception { + + SampleUser sampleUser = new SampleUser("name", "password"); + sampleUser.lastLogin = new Date(); + + ObjectMapper mapper = new ObjectMapper(); + ObjectNode node = (ObjectNode) mapper.readTree("{ \"name\" : \"another\" }"); + + SampleUser result = reader.readPut(node, sampleUser, mapper); + + assertThat(result.name, is("another")); + assertThat(result.password, notNullValue()); + assertThat(result.lastLogin, notNullValue()); + } + @Test // DATAREST-873 public void doesNotApplyInputToReadOnlyFields() throws Exception { @@ -550,6 +568,9 @@ public class DomainObjectReaderUnitTests { @JsonIgnore String password; Map relatedUsers; + @JsonProperty(access = READ_ONLY) + private Date lastLogin; + public SampleUser(String name, String password) { this.name = name;