Skip to content

Commit c46df6e

Browse files
author
Mathias Düsterhöft
committed
reproduce DATAREST-1006
1 parent afbffe4 commit c46df6e

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515
*/
1616
package org.springframework.data.rest.webmvc.json;
1717

18-
import static org.hamcrest.Matchers.*;
19-
import static org.junit.Assert.*;
20-
import static org.mockito.Mockito.*;
18+
import static com.fasterxml.jackson.annotation.JsonProperty.Access.READ_ONLY;
19+
import static org.hamcrest.Matchers.contains;
20+
import static org.hamcrest.Matchers.instanceOf;
21+
import static org.hamcrest.Matchers.is;
22+
import static org.hamcrest.Matchers.notNullValue;
23+
import static org.hamcrest.Matchers.nullValue;
24+
import static org.hamcrest.Matchers.sameInstance;
25+
import static org.junit.Assert.assertThat;
26+
import static org.mockito.Mockito.mock;
2127

2228
import lombok.AllArgsConstructor;
2329
import lombok.EqualsAndHashCode;
@@ -58,6 +64,7 @@
5864
import com.fasterxml.jackson.annotation.JsonAutoDetect;
5965
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
6066
import com.fasterxml.jackson.annotation.JsonIgnore;
67+
import com.fasterxml.jackson.annotation.JsonProperty;
6168
import com.fasterxml.jackson.databind.JsonNode;
6269
import com.fasterxml.jackson.databind.ObjectMapper;
6370
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
@@ -194,6 +201,22 @@ public void doesNotWipeIdAndVersionPropertyForPut() throws Exception {
194201
assertThat(result.version, is(1L));
195202
}
196203

204+
@Test //
205+
public void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception {
206+
207+
SampleUser sampleUser = new SampleUser("name", "password");
208+
sampleUser.lastLogin = new Date();
209+
210+
ObjectMapper mapper = new ObjectMapper();
211+
ObjectNode node = (ObjectNode) mapper.readTree("{ \"name\" : \"another\" }");
212+
213+
SampleUser result = reader.readPut(node, sampleUser, mapper);
214+
215+
assertThat(result.name, is("another"));
216+
assertThat(result.password, notNullValue());
217+
assertThat(result.lastLogin, notNullValue());
218+
}
219+
197220
@Test // DATAREST-873
198221
public void doesNotApplyInputToReadOnlyFields() throws Exception {
199222

@@ -510,6 +533,9 @@ static class SampleUser {
510533
@JsonIgnore String password;
511534
Map<String, SampleUser> relatedUsers;
512535

536+
@JsonProperty(access = READ_ONLY)
537+
private Date lastLogin;
538+
513539
public SampleUser(String name, String password) {
514540

515541
this.name = name;

0 commit comments

Comments
 (0)