Commit a5bd17c0 by Ryan Baxter

Remove check that does not apply Formatters to Collection in Feign Client parameters. Fixes #1526

parent a5e5f81d
...@@ -241,7 +241,6 @@ public class SpringMvcContract extends Contract.BaseContract ...@@ -241,7 +241,6 @@ public class SpringMvcContract extends Contract.BaseContract
} }
} }
if (isHttpAnnotation && data.indexToExpander().get(paramIndex) == null if (isHttpAnnotation && data.indexToExpander().get(paramIndex) == null
&& !isMultiValued(method.getParameterTypes()[paramIndex])
&& this.conversionService.canConvert( && this.conversionService.canConvert(
method.getParameterTypes()[paramIndex], String.class)) { method.getParameterTypes()[paramIndex], String.class)) {
data.indexToExpander().put(paramIndex, this.expander); data.indexToExpander().put(paramIndex, this.expander);
...@@ -249,13 +248,6 @@ public class SpringMvcContract extends Contract.BaseContract ...@@ -249,13 +248,6 @@ public class SpringMvcContract extends Contract.BaseContract
return isHttpAnnotation; return isHttpAnnotation;
} }
private boolean isMultiValued(Class<?> type) {
// Feign will deal with each element in a collection individually (with no
// expander as of 8.16.2, but we'd rather have no conversion than convert a
// collection to a String (which ends up being a csv).
return Collection.class.isAssignableFrom(type);
}
private void parseProduces(MethodMetadata md, Method method, private void parseProduces(MethodMetadata md, Method method,
RequestMapping annotation) { RequestMapping annotation) {
checkAtMostOne(method, annotation.produces(), "produces"); checkAtMostOne(method, annotation.produces(), "produces");
......
...@@ -294,7 +294,7 @@ public class SpringMvcContractTests { ...@@ -294,7 +294,7 @@ public class SpringMvcContractTests {
assertEquals("/test", data.template().url()); assertEquals("/test", data.template().url());
assertEquals("GET", data.template().method()); assertEquals("GET", data.template().method());
assertEquals("[{id}]", data.template().queries().get("id").toString()); assertEquals("[{id}]", data.template().queries().get("id").toString());
assertNull(data.indexToExpander().get(0)); assertNotNull(data.indexToExpander().get(0));
} }
@Test @Test
......
...@@ -29,6 +29,7 @@ import java.lang.reflect.Proxy; ...@@ -29,6 +29,7 @@ import java.lang.reflect.Proxy;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.Future; import java.util.concurrent.Future;
...@@ -138,6 +139,11 @@ public class FeignClientTests { ...@@ -138,6 +139,11 @@ public class FeignClientTests {
public OtherArg(String value) { public OtherArg(String value) {
this.value = value; this.value = value;
} }
@Override
public String toString() {
return value;
}
} }
@FeignClient(name = "localapp", configuration = TestClientConfig.class) @FeignClient(name = "localapp", configuration = TestClientConfig.class)
...@@ -186,6 +192,9 @@ public class FeignClientTests { ...@@ -186,6 +192,9 @@ public class FeignClientTests {
@RequestMapping(method = RequestMethod.GET, path = "/tostring2") @RequestMapping(method = RequestMethod.GET, path = "/tostring2")
String getToString(@RequestParam("arg") OtherArg arg); String getToString(@RequestParam("arg") OtherArg arg);
@RequestMapping(method = RequestMethod.GET, path = "/tostringcollection")
Collection<String> getToString(@RequestParam("arg") Collection<OtherArg> args);
} }
public static class TestClientConfig { public static class TestClientConfig {
...@@ -325,6 +334,9 @@ public class FeignClientTests { ...@@ -325,6 +334,9 @@ public class FeignClientTests {
@Override @Override
public String print(OtherArg object, Locale locale) { public String print(OtherArg object, Locale locale) {
if("foo".equals(object.value)) {
return "bar";
}
return object.value; return object.value;
} }
...@@ -417,6 +429,15 @@ public class FeignClientTests { ...@@ -417,6 +429,15 @@ public class FeignClientTests {
return arg.value; return arg.value;
} }
@RequestMapping(method = RequestMethod.GET, path = "/tostringcollection")
Collection<String> getToString(@RequestParam("arg") Collection<OtherArg> args) {
List<String> result = new ArrayList<>();
for(OtherArg arg : args) {
result.add(arg.value);
}
return result;
}
public static void main(String[] args) { public static void main(String[] args) {
new SpringApplicationBuilder(Application.class) new SpringApplicationBuilder(Application.class)
.properties("spring.application.name=feignclienttest", .properties("spring.application.name=feignclienttest",
...@@ -570,7 +591,14 @@ public class FeignClientTests { ...@@ -570,7 +591,14 @@ public class FeignClientTests {
assertEquals(Arg.A.toString(), testClient.getToString(Arg.A)); assertEquals(Arg.A.toString(), testClient.getToString(Arg.A));
assertEquals(Arg.B.toString(), testClient.getToString(Arg.B)); assertEquals(Arg.B.toString(), testClient.getToString(Arg.B));
assertEquals("foo", testClient.getToString(new OtherArg("foo"))); assertEquals("bar", testClient.getToString(new OtherArg("foo")));
List<OtherArg> args = new ArrayList<>();
args.add(new OtherArg("foo"));
args.add(new OtherArg("goo"));
List<String> expectedResult = new ArrayList<>();
expectedResult.add("bar");
expectedResult.add("goo");
assertEquals(expectedResult, testClient.getToString(args));
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment