'Spring Boot / FeignClient: POST Json Body

I currently try to implement a POST call to a backend which requires me to POST json as body.

Now I'm facing the issue that Feign does not pass the annotated Body to the backend but only empty data.

As soon as I add a single @Param or a Map, those values are passed and the client works fine.

To increase readability I'd prefer to annotate the method with the Body and get the values from my config instead of passing them as method parameter.

The following example should work according to the Feign Documentation:

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@Headers("Content-Type: " + MediaType.APPLICATION_JSON_VALUE)
@Body("%7B\n"
  + "  \"user\": \"${logintoken.user}\",\n"
  + "  \"pwd\": \"${logintoken.password}\",\n"
  + "%7D")
String getLoginToken();


Solution 1:[1]

It is a known bug:

https://github.com/OpenFeign/feign/issues/503

Try Unirest if you need body. Not declarative, rather a builder.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mentallurg