Optional request body should be supported by feign

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
dimwcommented, Jun 5, 2016

@spencergibb: Do you think you can drop a line and explain why this issue has been closed without any further comment?

2reactions
dyc87112commented, Nov 27, 2017

@sdhery https://github.com/OpenFeign/feign/pull/583 has not been accept,so you need compile feign by yourself,then write an RequestBodyParameterProcessor implements AnnotatedParameterProcessor interface to support this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional request body should be supported by feign · Issue #126
In Spring MVC it is possible to annotate body parameter as optional using @RequestBody(required = false) parameter annotation, ...
Read more >
Feign client support for optional request param - Stack Overflow
For example, I have an endpoint, but I am not finding a way to actually make the param1 optional using feign client. @GetMapping(path...
Read more >
Developers - Optional request body should be supported by feign -
In Spring MVC it is possible to annotate body parameter as optional using @RequestBody(required = false) parameter annotation, e.g.:
Read more >
Spring Cloud OpenFeign
Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it....
Read more >
How to configure fiegn clients to perform HTTP requests in ...
In this tutorial, we will discuss how to configure and customize OpenFeign clients to perform the HTTP functions GET, PUT, POST & DELETE....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found