Closed
Description
From @wanghongfei on August 12, 2016 4:14
I'm using Feign with Spring Cloud Netflix stack. In SpringMVC we can use POJO as request parameter which is very convenient:
@RequestMapping(value = "/group/list")
public List<AdvertGroupVO> list(AdvertGroupVO vo) throws AlanException {
return adGroupService.list(vo);
}
But in Feign I have to write lots of @RequestParam
:
@FeignClient(name = "fooService")
public interface foo {
@RequestMapping(value = "/group/list")
public List<AdvertGroupVO> list(@RequestParam Integer id,
@RequestParam String name,
@RequestParam ... ...);
}
I think it good for feign's user. Thanks!
Copied from original issue: OpenFeign/feign#438
Activity
codefromthecrypt commentedon Aug 12, 2016
In feign's DefaultContract, a parameter without any annotations is assumed to be processed by feign's Encoder, which can do what's been requested here. We can decide if this behavior makes sense or not.
wanghongfei commentedon Aug 12, 2016
Thanks for @adriancole 's reply. In current Spring Cloud Netflix Feign's implementation it seems feign doesn't encode POJO to HTTP request parameter by default, or there's something I do not know yet
codefromthecrypt commentedon Aug 12, 2016
@wanghongfei are you saying that you want something to literally write each field as a query parameter (ex via reflection)? If so, that would be a custom encoder and I don't think it is a high-reuse thing at this point.
codefromthecrypt commentedon Aug 12, 2016
closest thing in feign upstream is
@QueryMap
which explodes a map into query parameters. I'm not sure if that is supported in MVC@RequestParam
wanghongfei commentedon Aug 12, 2016
@adriancole Thanks, I'll try
@QueryMap
or define my own encoder.wongloong commentedon Dec 8, 2016
@wanghongfei 请问这个问题你最后怎么解决的?
asarkar commentedon Jun 25, 2017
@adriancole @wanghongfei My PR #1361 allows
@RequestParam
to be used without avalue
/name
and with aMap
. Not with a POJO, but that's the closest thing to POJO.barrer commentedon Aug 18, 2017
@wongloong
supporting POJO as request parameter
solution: http://www.itmuch.com/spring-cloud-sum/feign-multiple-params/
tips:
method = RequestMethod.POST
and@RequestBody
I tested successfully!
spencergibb commentedon Aug 18, 2017
Right, this issue is for a GET method, not post.
SeauWong commentedon Aug 18, 2017
yml:
MAVEN:
SendPoint(get method):
ReceivePoint(post method):
charlesvhe commentedon Mar 7, 2018
I use RequestInterceptor to solve this problem:
rmfish commentedon Jan 10, 2019
Create a custom SpringMvcContract bean which override processAnnotationsOnParameter method:
https://gist.github.com/rmfish/0ed59a9af6c05157be2a60c9acea2a10
ryanjbaxter commentedon Jan 14, 2019
I dont think this is still an issue.
eefnrowe commentedon Jan 15, 2019
@charlesvhe ^_^
server1 - feignRemote:
server2 - controller
LUCKYZHOUSTAR commentedon Jan 30, 2019
@eefnrowe thanks
maketubo commentedon Feb 19, 2020
@eefnrowe With java1.8 sun.net.www.protocol.http.HttpURLConnection or feign-okhttp 10.4.0, I need to empty requestBody like
template.body(Request.Body.empty());
aftertemplate.queries(queries);
then work fine. 我看到你那边把template.body(null);注释掉了是因为之前版本的httpclient没问题?cbjjensen commentedon Aug 31, 2020
@maketubo I changed it to
king555317 commentedon Apr 11, 2025
切换httpclient即可解决