-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add annotation that specify allowed sort properties [DATACMNS-966] #1422
Comments
Kazuki Shimizu commented I've submitted the PR |
Oliver Drotbohm commented I like the idea, I just wonder whether an annotation is a good idea here as I guess the list of properties could become a bit longer. Wondering whether some API on |
Marcel Overdijk commented I like the idea of allowed sort properties as well. Another thing that I would be interested in is to have aliases for sort fields. In our api we use snake case and I want users to provide something like |
Marcel Overdijk commented I'm using the @RequestMapping(method = GET, path = "/books", produces = HAL_JSON_VALUE)
public ResponseEntity<?> list(
@QuerydslPredicate(root = Book.class, bindings = BookPredicateBindings.class) Predicate predicate,
@PageableDefault(sort = "full_name", direction = Sort.Direction.ASC) @SortBindings(bindings = BookSortBindings.class) final Pageable pageable,
final PagedResourcesAssembler<Book> pagedResourcesAssembler) { The What do you think? |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
I implemented this using JEE validation: @Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
if (value == null) {
return true;
}
Sort sort;
if (value instanceof Sort) {
sort = (Sort) value;
} else if (value instanceof Pageable) {
sort = ((Pageable) value).getSort();
} else {
throw new UnexpectedTypeException(
"Expected org.springframework.data.domain.Sort or org.springframework.data.domain.Pageable"
);
}
return sort.stream().allMatch(order -> properties.contains(order.getProperty()));
} |
Kazuki Shimizu opened DATACMNS-966 and commented
I'll suggest to add annotation that specify allowed sort properties to limit an injection as follow:
When an invalid property is detected, i think better it is ignore from sort property.
What do you think for this suggestion ?
I will submit pull request at later.
Thanks.
Affects: 1.12.6 (Hopper SR6)
Referenced from: pull request #190
1 votes, 3 watchers
The text was updated successfully, but these errors were encountered: