Skip to content

Commit d2dfff3

Browse files
author
Mathias Düsterhöft
committed
skip all ignored json properties
to avoid to accidentally set them to null Revert "fixed with skipping ignored properties" This reverts commit 8d85c61. fixed with skipping ignored properties only working with jackson 2.8.7-SNAPSHOT see FasterXML/jackson-databind#935 reproduce DATAREST-1006
1 parent afbffe4 commit d2dfff3

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/MappedProperties.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ private MappedProperties(PersistentEntity<?, ?> entity, BeanDescription descript
6464

6565
for (BeanPropertyDefinition property : description.findProperties()) {
6666

67+
if (description.getIgnoredPropertyNames().contains(property.getName())) {
68+
continue;
69+
}
6770
PersistentProperty<?> persistentProperty = entity.getPersistentProperty(property.getInternalName());
6871

6972
if (persistentProperty != null) {

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 //DATAREST-1006
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)