Feign Client does not resolve Query parameter

Bee picture Bee · May 9, 2017 · Viewed 26.4k times · Source

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 call works fine. But isValidRole is not working properly as the request is eventually sent like this.

/Groups?filter=displayName+Eq+{roleName}"

Here {roleName} is not resolved. What am I missing here? Appreciate some help, as I'm clueless at this point.

Edit: 1 more question: Is there a way to avoid automatic url encoding of query parameters?

Answer

Frank.Chang picture Frank.Chang · Apr 30, 2019

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;
    ...
}