Feign Client does not allow Query parameter
Here is my interface.
public interface SCIMServiceStub {
@RequestLine("GET /Users/{id}")
SCIMUser getUser(@Param("id") String id);
@RequestLine("GET /Groups?filter=displayName+Eq+{roleName}")
SCIMGroup isValidRole(@Param("roleName") String roleName);
}
Here getUser
it is operating normally. But it isValidRole
does not work correctly, since the request is ultimately sent this way.
/Groups?filter=displayName+Eq+{roleName}"
There {roleName}
is not allowed. What am I missing here? Appreciate some help as I have no idea what at the moment.
Edit : Another question: Is there a way to avoid auto-encoding the URLs of the query parameters?
source to share
This seems to be caused by an already open bug - https://github.com/OpenFeign/feign/issues/424
As in the comments, you can define your own Param.Expander
as Param.Expander
below as a workaround.
@RequestLine("GET /Groups?filter={roleName}")
String isValidRole(@Param(value = "roleName", expander = PrefixExpander.class) String roleName);
static final class PrefixExpander implements Param.Expander {
@Override
public String expand(Object value) {
return "displayName+Eq+" + value;
}
}
source to share
A recent (2019.04) open release and spring doc says:
The OpenFeign @QueryMap annotation provides POJO support for use as maps of GET parameters.
Spring Cloud OpenFeign provides the equivalent @SpringQueryMap annotation, which is used to annotate a POJO or Map parameter as a map of query parameters since 2.1.0.
You can use it like this:
@GetMapping("user")
String getUser(@SpringQueryMap User user);
public class User {
private String name;
private int age;
...
}
source to share