DATAREST-1006 - MappedProperties now skips all ignored properties.
Original pull request: #258.
This commit is contained in:
committed by
Oliver Gierke
parent
b05b5721b6
commit
4207be4243
@@ -42,6 +42,7 @@ import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Mathias Düsterhöft
|
||||
*/
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
class MappedProperties {
|
||||
@@ -69,6 +70,10 @@ class MappedProperties {
|
||||
|
||||
for (BeanPropertyDefinition property : description.findProperties()) {
|
||||
|
||||
if (description.getIgnoredPropertyNames().contains(property.getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Optional<? extends PersistentProperty<?>> persistentProperty = //
|
||||
Optional.ofNullable(entity.getPersistentProperty(property.getInternalName()));
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonProperty.Access.READ_ONLY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -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).isEqualTo(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 {
|
||||
|
||||
@@ -551,6 +569,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;
|
||||
|
||||
Reference in New Issue
Block a user