DATAREST-1440 - Revisited removal of fields in incoming payloads.

We now only remove fields from the payload in case there's no @JsonAnySetter on the target entity.
This commit is contained in:
Oliver Drotbohm
2019-11-04 09:09:59 +01:00
parent 8689c1bb5b
commit 28f8e0d397
3 changed files with 74 additions and 19 deletions

View File

@@ -23,6 +23,7 @@ import org.springframework.data.annotation.Transient;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
import org.springframework.data.mapping.PersistentEntity;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
@@ -90,7 +91,7 @@ public class MappedPropertiesUnitTests {
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
assertThat(properties.hasPersistentPropertyForField("anotherReadOnlyProperty")).isFalse();
assertThat(properties.isWritableProperty("anotherReadOnlyProperty")).isFalse();
assertThat(properties.getPersistentProperty("readOnlyProperty")).isNull();
properties = MappedProperties.forSerialization(entity, mapper);
@@ -99,6 +100,21 @@ public class MappedPropertiesUnitTests {
assertThat(properties.getPersistentProperty("readOnlyProperty")).isNotNull();
}
@Test // DATAREST-1440
public void exposesExistanceOfCatchAllMethod() {
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(SampleWithJsonAnySetter.class);
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
assertThat(properties.isWritableProperty("someProperty")).isTrue();
assertThat(properties.isWritableProperty("readOnlyProperty")).isFalse();
assertThat(properties.isWritableProperty("anotherReadOnlyProperty")).isFalse();
// Due to @JsonAnySetter
assertThat(properties.isWritableProperty("someRandomProperty")).isTrue();
}
static class Sample {
public @Transient String notExposedBySpringData;
@@ -108,4 +124,14 @@ public class MappedPropertiesUnitTests {
public @JsonProperty(access = Access.READ_ONLY) String readOnlyProperty;
public @ReadOnlyProperty String anotherReadOnlyProperty;
}
static class SampleWithJsonAnySetter {
public String someProperty;
public @JsonProperty(access = Access.READ_ONLY) String readOnlyProperty;
public @ReadOnlyProperty String anotherReadOnlyProperty;
@JsonAnySetter
public void set(String key, String value) {}
}
}