spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

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

Open pheyken opened this issue 1 year ago • 1 comments

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 (https://github.com/jakartaee/persistence/issues/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!

pheyken avatar Sep 13 '24 13:09 pheyken

Any news on this being completed and closed?

dmarsh26 avatar Jan 31 '25 16:01 dmarsh26