DATAREST-1006 - MappedProperties now skips all ignored properties.

Original pull request: #258.
This commit is contained in:
Mathias Düsterhöft
2017-10-04 10:55:38 +02:00
committed by Oliver Gierke
parent 377ea346c8
commit 7704a435d9
2 changed files with 26 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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<String, SampleUser> relatedUsers;
@JsonProperty(access = READ_ONLY)
private Date lastLogin;
public SampleUser(String name, String password) {
this.name = name;