Skip to content

Commit 9a86fa8

Browse files
fixed query map with array parameter bug (OpenFeign#1220)
* fixed query map with array parameter bug
1 parent 1ffa9be commit 9a86fa8

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

core/src/main/java/feign/ReflectiveFeign.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ private RequestTemplate addQueryMapQueryParameters(Map<String, Object> queryMap,
312312
: encoded ? nextObject.toString()
313313
: UriUtils.encode(nextObject.toString()));
314314
}
315+
} else if (currValue instanceof Object[]) {
316+
for (Object value : (Object[]) currValue) {
317+
values.add(value == null ? null
318+
: encoded ? value.toString() : UriUtils.encode(value.toString()));
319+
}
315320
} else {
316321
values.add(currValue == null ? null
317322
: encoded ? currValue.toString() : UriUtils.encode(currValue.toString()));

core/src/test/java/feign/FeignTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import okhttp3.mockwebserver.MockWebServer;
2525
import okhttp3.mockwebserver.SocketPolicy;
2626
import okio.Buffer;
27+
import org.assertj.core.util.Maps;
2728
import org.junit.Rule;
2829
import org.junit.Test;
2930
import org.junit.rules.ExpectedException;
@@ -66,6 +67,18 @@ public void iterableQueryParams() throws Exception {
6667
.hasPath("/?1=user&2=apple&2=pear");
6768
}
6869

70+
@Test
71+
public void arrayQueryMapParams() throws Exception {
72+
server.enqueue(new MockResponse().setBody("foo"));
73+
74+
TestInterface api = new TestInterfaceBuilder().target("http://localhost:" + server.getPort());
75+
76+
api.queryArrParams(Maps.newHashMap("1", new String[] {"apple", "pear"}));
77+
78+
assertThat(server.takeRequest())
79+
.hasPath("/?1=apple&1=pear");
80+
}
81+
6982
@Test
7083
public void postTemplateParamsResolve() throws Exception {
7184
server.enqueue(new MockResponse().setBody("foo"));
@@ -947,6 +960,9 @@ void form(
947960
@RequestLine("GET /?1={1}&2={2}")
948961
Response queryParams(@Param("1") String one, @Param("2") Iterable<String> twos);
949962

963+
@RequestLine("GET /")
964+
Response queryArrParams(@QueryMap Map<String, String[]> twos);
965+
950966
@RequestLine("POST /?date={date}")
951967
void expand(@Param(value = "date", expander = DateToMillis.class) Date date);
952968

0 commit comments

Comments
 (0)