Nikitin
Nikitin

Reputation: 269

Feign pageable sort is not consumed by controller

I use feign to make request to another microservice.

@RequestMapping(method = RequestMethod.GET, value = "/orders/search")
    AbstractResponse<Page<OrderResponse>> searchOrders(Pageable pageable);

It results in calling

GET http://localhost:8090/orders/search?page=0&size=5&sort=id&sort=DESC

However, spring controller

@GetMapping("/search")
    public ResponseWrapper<Page<OrderResponse>> searchOrders(@PageableDefault(sort = "id", size = 5) Pageable pageable) {

Seems to not pay attention to second sort=desc and sets order to default(ASC)

When trying to do query manually like

GET http://localhost:8090/orders/search?page=0&size=6&sort=id,desc

It worked as expected(when using sort=id,desc)

How to make feign client send pageable requests that are supported by the controller?

Upvotes: 0

Views: 654

Answers (1)

Nikitin
Nikitin

Reputation: 269

Solved by adding @CollectionFormat(feign.CollectionFormat.CSV) to feign query, like

@RequestMapping(method = RequestMethod.GET, value = "/orders/search")
@CollectionFormat(feign.CollectionFormat.CSV)
    AbstractResponse<Page<OrderResponse>> searchOrders(Pageable pageable);

Upvotes: 1

Related Questions