-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring Data Pageable Sort in Feign Client #146
Comments
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. |
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. |
@ryanjbaxter I created a sample: https://github.com/jbrmg/openfeign-issue-146 . Please see the class 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 |
Also, encounter this issue, any suggestion? My workaround is extending the @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 |
@sebastian3456 the issue was solved here: OpenFeign/feign#930 |
We updated to OpenFeign 10.4.0 in this fix eecc51e Please reopen if this did not fix the issue |
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. |
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 |
Issue should be reopened. There was change in Feign that reintroduced the issue: OpenFeign/feign#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);
}
}
} |
Seeing the same issue as mentioned by @karbi when passing 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 |
Will verify. |
Was able to reproduce it. We'll need to introduce support for |
Hi, is it possible to make this change for Greenwich.SRX? |
We are no longer adding features to Greenwich |
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] 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! |
I guess Ill open a new bug, this one is close... |
@royremi I also got the same issue in Hoxton.SR7. It is solved after I add
|
I have similar problem.... My feign client and has this annotation CollectionFormat (feign.CollectionFormat.CSV)
If I build a project without SpringQueryMap, then I get the following error
|
Updated spring-cloud-version to version 3.0.2 helped |
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
The text was updated successfully, but these errors were encountered: