DATAREST-1248 - SortTranslator now considers read-only properties sortable.
MappedProperties now exposes a factory method that uses the Jackson introspector for serialization (instead of deserialization) which now also includes read-only properties. Previously, read-only ones were not considered as they are excluded from the metadata if it is looked up for deserialization.
This commit is contained in:
@@ -37,7 +37,7 @@ public class MappedPropertiesUnitTests {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Sample.class);
|
||||
MappedProperties properties = MappedProperties.fromJacksonProperties(entity, mapper);
|
||||
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() {
|
||||
@@ -75,6 +75,15 @@ public class MappedPropertiesUnitTests {
|
||||
assertThat(properties.getPersistentProperty("readOnlyProperty")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-1248
|
||||
public void doesNotExcludeReadOnlyPropertiesForSerialization() {
|
||||
|
||||
MappedProperties properties = MappedProperties.forSerialization(entity, mapper);
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("readOnlyProperty")).isTrue();
|
||||
assertThat(properties.getPersistentProperty("readOnlyProperty")).isNotNull();
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
|
||||
public @Transient String notExposedBySpringData;
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.rest.webmvc.json.JacksonMappingAwareSortTranslat
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty.Access;
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -171,12 +172,22 @@ public class SortTranslatorUnitTests {
|
||||
assertThat(translatedSort.getOrderFor("burrito.embedded.name")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-1248
|
||||
public void allowsSortingByReadOnlyProperty() {
|
||||
|
||||
Sort sort = sortTranslator.translateSort(Sort.by("readOnly"),
|
||||
mappingContext.getRequiredPersistentEntity(Plain.class));
|
||||
|
||||
assertThat(sort.getOrderFor("readOnly")).isNotNull();
|
||||
}
|
||||
|
||||
static class Plain {
|
||||
|
||||
public String name;
|
||||
public Embedded embedded;
|
||||
@Reference public Embedded refEmbedded;
|
||||
@Reference public AnotherRootEntity association;
|
||||
@JsonProperty(access = Access.READ_ONLY) public String readOnly;
|
||||
}
|
||||
|
||||
static class UnwrapEmbedded {
|
||||
|
||||
Reference in New Issue
Block a user