The new pageable support in version 2.1.1 can't handle the sorting in the pageable.

Here is my code: @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Page<T> findAll(@RequestParam("parameters") Map<String, Collection<String>> parameters, @RequestBody Pageable page);

When I call this method size and page parameters are mapped fine, sorting is not working. Let's expect I have a pageable with a sort on id,asc. So the request url should look like example.com/api/test?page=0&size=10&sort=id,ASC But the actual request url looks like example.com/api/test?page=0&size=10&sort=id&sort=ASC

Comment From: ryanjbaxter

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: jbrmg

@ryanjbaxter I created a sample: https://github.com/jbrmg/openfeign-issue-146 . Please see the class Issue146Test for the executable test code. The test fails as expected.

As stated by @sebastian3456, the problem is that the sort query param is split into two parameters in the request url. This however does not get parsed by other spring boot services. This seems to be caused by the CollectionFormat for the RequestTemplate being CollectionFormat.EXPLODED, which performs a split by , on the original query param set by the PageableQueryEncoder.

Comment From: colinzhy

Also, encounter this issue, any suggestion?

My workaround is extending the PageableSpringEncoder, override the encode method and update the collectionFormat to CollectionFormat.CSV

  @Override
  public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
    template.collectionFormat(CollectionFormat.CSV);
    super.encode(object, bodyType, template);
  }

Any better solution? I know we can set collectionFormat in @RequestLine , how about to use Spring?

Comment From: nciriglianoupgrade

@sebastian3456 the issue was solved here: https://github.com/OpenFeign/feign/pull/930 please update io.github.openfeign dependencies to a higher version than 10.2.0 (last version with this bug)

Comment From: ryanjbaxter

We updated to OpenFeign 10.4.0 in this fix https://github.com/spring-cloud/spring-cloud-openfeign/commit/eecc51e69534385a8d8cf5ee9b20c88d7fd39139

Please reopen if this did not fix the issue

Comment From: golartes

Is that really works now? I use spring-cloud-starter-openfeign 2.2.2.RELEASE with feign-core 10.7.4. And I have the same problem and only WA by @colinzhy helps me now.

Comment From: rvervaek

I can verify @golartes comment. I'm too using spring-cloud-starter-openfeign 2.2.2.RELEASE which uses feign-core 10.7.4.

I'm experiencing the same issue. The sort queryparameter is being expanded by the QueryTemplate class in feign-core, which is not the desired behavior since the documentation states that sort parameters values should/can be provided in CSV format: https://docs.spring.io/spring-data/commons/docs/current/reference/html/#core.web.basic.paging-and-sorting

Comment From: karbi

Issue should be reopened. There was change in Feign that reintroduced the issue: https://github.com/OpenFeign/feign/pull/1138

Proper way to pass collection parameters is separating by commas and specifing collection format. When using raw Feign library this could be accomplished by passing collectionFormat parameter in @RequestLine annotation.

Possible solution for Spring Cloud integration could be creating annotation for specifing collection format and hadling in SpringMvcContract.

Here is my workaround.

@Configuration
public class CsvFormatConfiguration {

    @Autowired(required = false)
    private List<AnnotatedParameterProcessor> parameterProcessors = new ArrayList<>();

    @Bean
    public Contract feignContract(final ConversionService feignConversionService) {
        return new CsvContract(this.parameterProcessors, feignConversionService);
    }

    public static class CsvContract extends SpringMvcContract {

        public CsvContract(final List<AnnotatedParameterProcessor> annotatedParameterProcessors, final ConversionService conversionService) {
            super(annotatedParameterProcessors, conversionService);
        }

        @Override
        protected void processAnnotationOnMethod(final MethodMetadata data, final Annotation methodAnnotation, final Method method) {
            super.processAnnotationOnMethod(data, methodAnnotation, method);

            data.template().collectionFormat(CollectionFormat.CSV);
        }
    }
}

Comment From: nickcaballero-mm

Seeing the same issue as mentioned by @karbi when passing Pageable. A custom encoder can also be used as a workaround, temporarily changing the default collection format:

public class CustomPageableEncoder extends PageableSpringEncoder {

    public CustomPageableEncoder(Encoder delegate) {
        super(delegate);
    }

    @Override
    public void encode(Object object, Type bodyType, RequestTemplate template) {
        CollectionFormat previousFormat = template.collectionFormat();
        template.collectionFormat(CollectionFormat.CSV);
        super.encode(object, bodyType, template);
        template.collectionFormat(previousFormat);
    }
}

Update: After testing the above, it only really works for a single sort parameter. Multiple sort parameters still breaks. As a workaround, I've resorted to encoding the comma to %2C.

Comment From: OlgaMaciaszek

Will verify.

Comment From: OlgaMaciaszek

Was able to reproduce it. We'll need to introduce support for CollectionFormat in order to make it work.

Comment From: jonseah

Hi, is it possible to make this change for Greenwich.SRX?

Comment From: spencergibb

We are no longer adding features to Greenwich

Comment From: royremi

I don't know if it is related, but we upgraded from Hoxton.SR2 to Hoxton.SR7 and we started to have an issue with sorting.

When I look at the request I see something like that

Hoxton.SR2 = /api/v1/driver/?statuses=Active&page=0&size=10&sort=driver_filename,ASC] Hoxton.SR7 = /api/v1/driver/?statuses=Active&page=0&size=10&sort=driver_filename&sort=ASC]

if you look you have 2 times the same request parameter. sort=driver_filename&sort=ASC.

Is something change in config I need to fix or its a bug on your side?

Thank you!

Comment From: royremi

I guess Ill open a new bug, this one is close...

Comment From: rezanachmad

@royremi I also got the same issue in Hoxton.SR7. It is solved after I add @CollectionFormat(feign.CollectionFormat.CSV) in @GetMapping as shown in the documentation

        @FeignClient(name = "demo")
    protected interface PageableFeignClient {

        @CollectionFormat(feign.CollectionFormat.CSV)
        @GetMapping(path = "/page")
        ResponseEntity performRequest(Pageable page);
    }

Comment From: alabotski

I have similar problem....

My feign client and has this annotation CollectionFormat (feign.CollectionFormat.CSV) But it does not help me = (

@FeignClient(name = "BaseCaseFeignClient", url = "${feign.services.host-backend.url}")
public interface BaseCaseFeignClient {
    @PostMapping("/api/cases/base/search")
    @CollectionFormat (feign.CollectionFormat.CSV)
    Page<FoundRecordDto> searchCases(@RequestBody FilterSpecification filter, @SpringQueryMap Pageable pageable);
}

If I build a project without SpringQueryMap, then I get the following error

Page<FoundRecordDto> searchCases(@RequestBody FilterSpecification filter, Pageable pageable);

Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.data.domain.Page ru..BaseCaseFeignClient.searchCases(ru.ilter.shared.basecase.search.FilterSpecification,org.springframework.data.domain.Pageable)
Warnings:

Comment From: alabotski

Updated spring-cloud-version to version 3.0.2 helped