feign
feign copied to clipboard
FeignClient not sending proper form url encoded request
We have a scenario where a POST application/form-url-encoded request is to be sent to an API endpoint. And we are using @FeignClient annotated interface having a @PostMapping annotated function which takes in a POJO class as an argument such that the attributes of the class will be set as key value pairs of form data.
The issue is that the POJO class ( which is an argument to the function ) is derived from a base class. Due to which the form data posted to the API endpoint does not contain the attributes of the base class.
It works fine if the argument to @PostMapping function is a simple POJO class which doesn't extend any other class.
Can you please suggest a solution to the issue?
@techestop4u
When using the Spring extensions, a custom Encoder is registered that is responsible for dealing with bean driven parsing. I recommend checking in with Spring Cloud OpenFeign on Stack Overflow first.
If that doesn't pan out, Feign has a special library for dealing with forms, feign-form that may help you.
Just coming across this at random, but note that Spring Cloud OpenFeign depends on feign-form. The encoding is performed by feign-form’s PojoUtil
, which relies on type.getDeclaredFields()
, so it won’t retrieve parent fields.
It also presents some other strange quirks, such as ignoring final
fields, see OpenFeign/feign-form/issues/77
(maybe this issue should be moved to feign-form?)