-
Notifications
You must be signed in to change notification settings - Fork 682
PageableHandlerMethodArgumentResolver
should fall back to unpaged Pageable
if necessary
#3094
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
Milestone
Comments
It should be fixed by #2865. |
PageableHandlerMethodArgumentResolver
should fallback to unpaged Pageable
if necessary
PageableHandlerMethodArgumentResolver
should fallback to unpaged Pageable
if necessaryPageableHandlerMethodArgumentResolver
should fall back to unpaged Pageable
if necessary
natedanner
pushed a commit
to natedanner/spring-projects__spring-data-commons
that referenced
this issue
May 20, 2024
The (Reactive)PageableHandlerMethodArgumentResolver now falls back to a unpaged Pageable instance with a resolved sort if the the resolved Pageable is unpaged. Fixes: spring-projectsGH-3094 Original pull request: spring-projectsGH-2865
natedanner
pushed a commit
to natedanner/spring-projects__spring-data-commons
that referenced
this issue
May 20, 2024
Ternary ifs and less nesting. Related: spring-projectsGH-3094 Original pull request: spring-projectsGH-2865
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi team,
I have the following use case, that I believe will be fairly common for rest endpoints.
Use Case
I have a use case for a controller that can support pagination and sorting, but both are optional.
/foos
will return all resources/foos?page=2&size=3
will return page 2, size 3 of resources, without sorting./foos?sort=bar,desc
will return all resources, sorted by property bar descending./foos?page=2&size=3&sort=bar,desc
will return page 2, size 3 of the sorted resource by property bar, descending.Issue
I have set
PageableHandlerMethodArgumentResolverSupport.fallbackPageable
toPageable.unpaged()
.This works for
/foos
, returning all items without sorting.But there is an error when attempting
/foos?sort=bar,desc
due tospring-data-commons/src/main/java/org/springframework/data/web/PageableHandlerMethodArgumentResolver.java
Lines 85 to 87 in 2f43bd5
PageRequest
fails onpageable.getPageNumber()
throwingUnsupportedOperationException
I would have expected the above code to have looked something like
as this would allow returning all items in the resource with sorting.
This feels like a bug to me, the ability to sort a resource shouldn't require pagination.
Fallback to unpaged property
As an aside, it seems strange that the
fallbackPageable
is the only property not settable via configurationhttps://github.com/spring-projects/spring-boot/blob/22386f4ddd3589a7059891026b0fb512a46237e4/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java#L61-L74
A property like
spring.data.web.pageable.default-unpaged=true
that can set the fallbackPageable inSpringDataWebAutoConfiguration.pageableCustomizer()
toPageable.unpaged()
could make sense to me.Thanks,
Josh
The text was updated successfully, but these errors were encountered: