From c46df6e66b1bfeb27f81d9e7c03e15b699f1019a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20D=C3=BCsterh=C3=B6ft?= Date: Fri, 10 Feb 2017 09:12:14 +0100 Subject: [PATCH] reproduce DATAREST-1006 --- .../json/DomainObjectReaderUnitTests.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) 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 2527ca50e..940d4504f 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,9 +15,15 @@ */ package org.springframework.data.rest.webmvc.json; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static com.fasterxml.jackson.annotation.JsonProperty.Access.READ_ONLY; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.sameInstance; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -58,6 +64,7 @@ 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.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy; @@ -194,6 +201,22 @@ public void doesNotWipeIdAndVersionPropertyForPut() throws Exception { assertThat(result.version, is(1L)); } + @Test // + 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 { @@ -510,6 +533,9 @@ static class SampleUser { @JsonIgnore String password; Map relatedUsers; + @JsonProperty(access = READ_ONLY) + private Date lastLogin; + public SampleUser(String name, String password) { this.name = name;