Open hesselapplications opened 9 months ago
We have Pageable
parameters on Spring Cloud OpenFeign client methods. The lack of Pageable
support blocks us from switching to HTTP interface clients. I'm experimenting with this work around. Define a custom argument resolver:
public class PageableArgumentResolver implements HttpServiceArgumentResolver {
@Override
public boolean resolve(Object argument, MethodParameter parameter, HttpRequestValues.Builder requestValues) {
if (!parameter.getParameterType().equals(Pageable.class)) {
return false;
}
if (argument != null) {
var pageable = (Pageable) argument;
if (pageable.isPaged()) {
requestValues.addRequestParameter("page", String.valueOf(pageable.getPageNumber()));
requestValues.addRequestParameter("size", String.valueOf(pageable.getPageSize()));
}
Sort sort = pageable.getSort();
if (sort.isSorted()) {
for (Sort.Order order : sort) {
requestValues.addRequestParameter("sort", order.getProperty() + "," + order.getDirection().name());
}
}
}
return true;
}
}
Invoke the HttpServiceProxyFactory.Builder
customArgumentResolver method to register the custom argument resolver.
We started implementing an HTTP client using an HTTP interface client as well and just stumbled upon this issue after researching how to implement pagination.
I guess the answer is: We can't. Unfortunate 😄
So +1 for this issue.
It would be great if http interface clients had support for:
This would bring feature parity for what is supported in controllers today. I believe spring openfeign clients support this as well
Original: https://github.com/spring-projects/spring-framework/issues/32286