I am using a FeignClient and a GetMapping to interact with an external system.
My GetMapping is defined as:
@GetMapping(value = "/path/to/endpoint?fields=[\"nm\",\"label\"]")
public String hitEndpoint() {}
Debug shows that the endpoint is being called with:
https://url/path/to/endpoint?fields=[%22nm%22&fields=%22label%22]
Which is failing because the endpoint expects valid json for the fields parameter:
https://url/path/to/endpoint?fields=[%22nm%22,%22label%22]
How do I convince GetMapping to make the request correctly?
Thanks for any help.
Although I think its better to pass
JSONas body of aPOSTmethod to your controller. But if you insist on doing this I can propose to you 2 solutions:First Solution
Encode your
JSONarray into Percent-encoding so you can send it viaURL.For example, your array will be like this:
["nm","label"]->%5B%22nm%22%2C%22label%22%5DI used this online tool to encode it.
Second Solution
Base64andGETit via URL to your controller.Base64string in the controller and parse it as aJSONarray.