Spring Data TypedSort with nested property criteria support

411 views Asked by At

I am trying to define the following sort criteria:

TypedSort<Task> typedSort = Sort.sort(Task.class);
Sort typedSortCriteria = typedSort.by(task -> task.getAssignee().getLastName())
    .descending();

But I'm getting a compilation exception:

The method by(Function<Task,String>) is ambiguous for the type Sort.TypedSort<Task>

Is it possible to define a nested property typed sort criteria?

PS. I submitted an issue to the Spring Data Commons repository to clarify this point as well:

https://github.com/spring-projects/spring-data-commons/issues/2380

1

There are 1 answers

0
Gerardo Roza On

My bad, it seems I just had to cast the Function explicitly:

typedSort.by((Function<Task, String>) task -> task.getAssignee().getLastName())
    .descending();

Hope this helps anyway, as there is no documentation about this particular case at this moment.