Feign Client does not resolve Query parameter
As the recent(2019.04) open feign issue and spring doc say:
The OpenFeign @QueryMap annotation provides support for POJOs to be used as GET parameter maps.
Spring Cloud OpenFeign provides an equivalent @SpringQueryMap annotation, which is used to annotate a POJO or Map parameter as a query parameter map 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;
...
}
Working fine using @QueryMap
URL: /api/v1/task/search?status=PENDING&size=20&page=0
Map<String, String> parameters = new LinkedHashMap<>()
parameters.put("status", "PENDING")
parameters.put("size", "20")
parameters.put("page", "0")
def tasks = restClientFactory.taskApiClient.searchTasks(parameters)
Inside Client Interface
@RequestLine("GET /api/v1/task/search?{parameters}")
List<Task> searchTasks(@QueryMap Map<String, String> parameters)
It seems to be caused by a bug that is already opened - https://github.com/OpenFeign/feign/issues/424
Like in comments, you can define your own Param.Expander
something like 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;
}
}
With Spring feign client below works fine :
@GetMapping("/Groups?filter=displayName+Eq+{roleName}")
SCIMGroup isValidRole(@PathVariable(value = "roleName") String roleName);