OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.48k stars 1.93k forks source link

GET Query Param MAP to JSON object #1591

Closed Sironheart closed 2 years ago

Sironheart commented 2 years ago

I'm currently trying to talk to an old PHP API, which accepts filters as following ?filter={"foo":"bar", "fizz":"buzz"}

I have not been able to get a result like this.

My client looks the following:

interface FooClient {
    @RequestMapping(method = [RequestMethod.GET], value = ["/v3/foo"])
    fun foo(@SpringQueryMap(encoded = true) filter: StableQueryParams): StableMoviesResponse?
}

The POJO is a Kotlin Dataclass:

data class StableQueryParams(
    val filter: Map<String, String>,
)

Unluckily this leads to the following output: /v3/movies?filter={foo=bar, fizz=buzz}

Is it possible to get these kinds of JSON output for Maps or Sub classes? How would I be able to to this?

Thanks for your help in advance :)

Sironheart commented 2 years ago

I found a solution. It is a matter of changing the QueryMap-Object to @RequestParam filter: String and parsing the JSON by hand.