Skip to content

Allow specifying null handling for 'sort' query params as well as setting a default #3152

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
pheyken opened this issue Sep 13, 2024 · 1 comment · May be fixed by #3153
Open

Allow specifying null handling for 'sort' query params as well as setting a default #3152

pheyken opened this issue Sep 13, 2024 · 1 comment · May be fixed by #3153
Assignees
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@pheyken
Copy link

pheyken commented Sep 13, 2024

Hi,

a few years ago, the initial feature request was created to allow setting the null handling via the 'sort' query parameters.

In the mean time, this was picked up by jakartaee/persistence (jakartaee/persistence#76) and, as far as I can tell, there is progress made in getting this into spring-data-jpa for 3.4.0.

Following addition to the @SortDefault annotation could be made:

@SortDefault(
    value = "property",
    direction = Sort.Direction.DESC,
    nullHandling = Sort.NullHandling.NULLS_LAST
)

Following addition to the sort query param could be made:
?sort=(propertyName)+(,ASC|,DESC)?(,ignorecase)?(,nullsnative|,nullsfirst|,nullslast)?

The null handling would be optional, and work in any combination with the remaining, optional parameters. A few, valid examples would be:

?sort=property1

?sort=property1,property2,nullsfirst

?sort=property1,asc,nullslast

?sort=property1,property2,desc,ignorecase,nullsnative

As the SortHandlerMethodArgumentResolverSupport is part of spring-data-commons, I opted to create the issue here again to have an issue number in this project, hope this was the right approach.

Edit: A draft PR implementing the suggestion can be found here: #3153. Happy to hear any suggestions you might have!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 13, 2024
pheyken added a commit to pheyken/spring-data-commons that referenced this issue Sep 13, 2024
pheyken added a commit to pheyken/spring-data-commons that referenced this issue Sep 13, 2024
pheyken added a commit to pheyken/spring-data-commons that referenced this issue Sep 13, 2024
@pheyken pheyken linked a pull request Sep 13, 2024 that will close this issue
4 tasks
@mp911de mp911de added type: enhancement A general enhancement status: ideal-for-contribution An issue that a contributor can help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 16, 2024
@mp911de mp911de self-assigned this Sep 16, 2024
@dmarsh26
Copy link

Any news on this being completed and closed?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants