Skip to content

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

Open
@pheyken

Description

@pheyken

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!

Activity

added 3 commits that reference this issue on Sep 13, 2024
bb971fa
afb6d7f
8134da8
linked a pull request that will close this issue on Sep 13, 2024
self-assigned this
on Sep 16, 2024
dmarsh26

dmarsh26 commented on Jan 31, 2025

@dmarsh26

Any news on this being completed and closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @mp911de@dmarsh26@spring-projects-issues@pheyken

    Issue actions

      Allow specifying null handling for 'sort' query params as well as setting a default · Issue #3152 · spring-projects/spring-data-commons