Search code examples
kotlinspring-cloud-feignfeign

@QueryMap pass parameters in the body


I have a simple POJO:

class FilterDTO(
    open var page: Int = 0,
    open var size: Int = 20
)

And a simple Feign Client:

@FeignClient(name = "feign-client", url = "\${feign.url.client}")
interface FeignClient{

    @GetMapping("get/{id}")
    fun getById(@PathVariable("id") id: String, @QueryMap(encoded = true) filter: FilterDTO): Any

}

According to the Pull Request #667, I was expecting this to be translated as:

---> GET http://my.service.com/get/123?page=0&size=20 HTTP/1.1
Content-Length: 64
Content-Type: application/json

---> END HTTP (64-byte body)
<--- HTTP/1.1 200 Ok (807ms)
allow: GET

// ...

{"response": "foo"}
<--- END HTTP (108-byte body)

But instead I'm getting:

---> GET http://my.service.com/get/123 HTTP/1.1
Content-Length: 64
Content-Type: application/json

{"page":0,"size":2}
---> END HTTP (64-byte body)
<--- HTTP/1.1 405 Method Not Allowed (807ms)
allow: GET
cache-control: no-cache, no-store, max-age=0, must-revalidate
//..

{"timestamp":1628783721302,"status":405,"error":"Method Not Allowed","path":"/get/123"}
<--- END HTTP (108-byte body)

Notice the @QueryMap parameter is being passed in the body of the request instead being passed as queryString.

The endpoint it is trying to call is defined as:

    @GetMapping("/get/{id}")
    fun getById(
            @PathVariable("id")
            id: String,
            filter: FilterDTO
    )

What am I missing? How can I use @QueryMap to pass it as query parameter?


Solution

  • Found out that using spring-cloud-openfeign I should use @SpringQueryMap instead of @QueryMap as stated in the docs