Skip to content

Commit e60bdac

Browse files
committed
DATAREST-1280 Add support sort collection resource by associated property.
Closes spring-projects#1641 Related tickets spring-projects#1386 spring-projects#1343
1 parent 2b207b1 commit e60bdac

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

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

-4
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ private List<String> mapPropertyPath(PersistentEntity<?, ?> rootEntity, List<Str
192192

193193
for (PersistentProperty<?> persistentProperty : persistentProperties) {
194194

195-
if (associations.isLinkableAssociation(persistentProperty)) {
196-
return Collections.emptyList();
197-
}
198-
199195
persistentPropertyPath.add(persistentProperty.getName());
200196
}
201197

spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 original author or authors.
2+
* Copyright 2016-2023 original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,19 +117,19 @@ void shouldMapKnownNestedProperties() {
117117
assertThat(translatedSort.getOrderFor("embedded.someInterface")).isNotNull();
118118
}
119119

120-
@Test // DATAREST-910
121-
void shouldSkipWrongNestedProperties() {
120+
@Test // DATAREST-1280
121+
void shouldKnownAssociationProperties() {
122122

123-
Sort translatedSort = sortTranslator.translateSort(Sort.by("embedded.unknown"),
123+
Sort translatedSort = sortTranslator.translateSort(Sort.by("association.name"),
124124
mappingContext.getRequiredPersistentEntity(Plain.class));
125125

126-
assertThat(translatedSort).isEqualTo(Sort.unsorted());
126+
assertTrue(translatedSort.isSorted());
127127
}
128128

129-
@Test // DATAREST-910, DATAREST-976
130-
void shouldSkipKnownAssociationProperties() {
129+
@Test // DATAREST-910
130+
void shouldSkipWrongNestedProperties() {
131131

132-
Sort translatedSort = sortTranslator.translateSort(Sort.by("association.name"),
132+
Sort translatedSort = sortTranslator.translateSort(Sort.by("embedded.unknown"),
133133
mappingContext.getRequiredPersistentEntity(Plain.class));
134134

135135
assertThat(translatedSort).isEqualTo(Sort.unsorted());

0 commit comments

Comments
 (0)