0

I'm declaring FeignClient with Spring Cloud OpenFeign version 4.0.1. The API I'm calling expects in request body primitive JSON string value (e.g. "something") as a string in quotes. But I'm struggling with implementing it using Feign.

Code sample:

@FeignClient(value = "client", url = "https://${example.host}:${example.port}/api/2/", dismiss404 = true)
public interface ExampleClient {
    @GetMapping(value = "/path/to/resource", produces = MediaType.APPLICATION_JSON_VALUE)
    String getResourceValue();

    @PutMapping(value = "/path/to/resource", consumes = MediaType.APPLICATION_JSON_VALUE)
    void setResourceValue(@RequestBody String hostname);
}

The code just serializes the string to body as plain text without adding quotes (it is even stripping them). In deserialization it returns the string including quotes and it is not removing them. I know this is intended behavior but how could I achieve that client will serialize and deserialize simple String value as valid JSON?

The only workaround I was able to find was to replace String type by Jackson TextNode class. But it is not very elegant solution. It was also possible by setting JacksonEncoder instead of Spring implementation but then I loose other features.

kyberpunk
  • 1
  • 1

0 Answers0