spring-cloud / spring-cloud-openfeign

Support for using OpenFeign in Spring Cloud apps
Apache License 2.0
1.17k stars 756 forks source link

Issue with registering method parameter hints #1021

Closed OlgaMaciaszek closed 2 months ago

OlgaMaciaszek commented 2 months ago

Initially reported in https://github.com/spring-cloud/spring-cloud-openfeign/issues/860#issuecomment-1548713643.

Calling client generated with the sample: https://github.com/CodeQualIT/CQITFunctions, causes feign.codec.EncodeException: Could not write request: no suitable HttpMessageConverter found for request type [nl.cqit.function.poc.java.helloworld.api.model.Person] and content type [application/json].

Possibly related to class generation.

CC @CC007

OlgaMaciaszek commented 2 months ago

@CC007 You need to add @RegisterReflectionForBinding(nl.cqit.function.poc.java.helloworld.api.model.Person.class) and not for nl.cqit.function.poc.java.boxedhello.api.model.Person.class as in the sample, since it's the former that is in the OF client method signature. After changing it, the sample works correctly.

This is a simple and fast workaround for the issue, however, I will also take a look at registering reflection hints for classes used in OF method signatures automatically.

OlgaMaciaszek commented 2 months ago

This should actually work already as per https://github.com/spring-cloud/spring-cloud-openfeign/commit/06192a575cac356c2e6c826f4995976c24a337fb. Will need to verify why it doesn't work in the sample.

OlgaMaciaszek commented 2 months ago

Given that we can reasonably assume that any method defined in either a @FeignClient interface or a supertype interface is supposed to be part of the API, we should register all such methods for reflection and not only the ones declared for the annotated interface. That will fix the issue.