-
Couldn't load subscription status.
- Fork 1.9k
Description
Currently Feign will not resolve methods with BuildEncodedTemplateFromArgs if they have 0 or more than 1 body parameters, which prevents the usage of custom Feign encoders. There are use cases though where an application (or library) needs a client with a custom encoder and needs that encoder triggered even if the client method has 0 or more than 1 "body parameters" (parameters not annotated with Feign annotations or custom annotations registered in Feign using DeclarativeContract.registerParameterAnnotation).
A few examples of this use case:
- An application needs a Feign client whose request payload is defined entirely by a custom Feign encoder even if no parameter is declared at the client method. In this case, even with no presence of body parameter the encoder will know how to define the request payload (based on the method name, method return type, and other optional metadata provided by annotations).
- An application needs a Feign client whose request payload is defined by a custom Feign encoder plus one or more parameters, all of them annotated with custom annotation(s) registered in Feign using
DeclarativeContract.registerParameterAnnotation. In this case the encoder will use all the parameters, plus metadata in their respective annotations, to properly define the request message payload.
To be more specific, this issue is required to support certain use cases in Mocca. This improvement would help to simplify Mocca's API a lot.
We are also open to contributing a PR to implement this feature, if Feign team first accesses this issue and let us know we should do so.
By the way, we tried first to address this use case by creating a custom Feign Contract implementation, but that was not possible because overwriting a parseAndValidateMetadata requires instantiating MethodMetadata and that class has a package-private constructor (besides being final too).
Please let us know your thoughts on this and, if you believe this is an useful enhancement to have, if we can go ahead and provide a PR addressing this (or if you prefer to do so yourselves, please let us know the timeline to provide it).
Thanks.