Open
Description
In Spring MVC it is possible to annotate body parameter as optional using @RequestBody(required = false)
parameter annotation, e.g.:
@FeignClient("foo-service")
public interface FooService {
@RequestMapping(value = "/foo", method = RequestMethod.POST)
void doFoo(@RequestBody(required = false) FilterDto filter);
}
However, Spring-Feign contract does not consider the optionality flag which leads to an IllegalStateException on proxy bootstrapping in consumer when calling something like:
fooService.doFoo(null);
java.lang.IllegalArgumentException: Body parameter 0 was null
at feign.Util.checkArgument(Util.java:102)
at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:323)
at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:213)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:72)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
It is expected that null
can be passed as parameter since it is optional.
Using:
- spring-cloud-starter-feign:1.1.0.RELEASE
- feign-core:8.16.2