OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.49k stars 1.93k forks source link

Expand Params into body behaves differently in Feign 10 #965

Closed ghost closed 5 years ago

ghost commented 5 years ago

For the following request the resulting request body differs between Feign 9.x and Feign 10.x

@RequestLine("POST /api/v1/test")
@Body("%7B\"jsonField\":{list}%7D")
ResponseDto postRequest(@Param("list") List<Long> list);

For Feign 9 the list param is expanded into the body using AbstractCollection.toString() which is done here: https://github.com/OpenFeign/feign/blob/9.7.0/core/src/main/java/feign/RequestTemplate.java#L147

For Feign 10 instead an expand() method from Feign is used to serialize the list param: https://github.com/OpenFeign/feign/blob/master/core/src/main/java/feign/template/Template.java#L104

As a result in Feign 9 the list param is encoded with the surrounding brackets [1,2,3] but for Feign 10 it is encoded without brackets 1,2,3.

Of course it is possible to adjust the @Body annotation and just add the brackets if using Feign 10, but I suppose this change was not intended and the behaviour should be changed?

kdavisk6 commented 5 years ago

@dwi-di

What you are experiencing is the desired behavior. Template processing in 10.x has been modified to adhere to RFC 6570: URI Template. This decision was made because much of the template handling prior was inconsistent. We've discovered that, since making this change, there a number of users who relied on this inconsistent, undocumented behavior, as it appears you have as well.

List expansion follows the requirements outlined in the 3.2.2. Simple String Expansion: {var}, section of the specification, where each value in the list is expanded and split using a comma (,):

{list}             red,green,blue

To restore the previous behavior, you will need to add the brackets directly to the template.

ghost commented 5 years ago

ok, thank you for the detailed explanation.