diff --git a/src/main/java/com/amadeus/Params.java b/src/main/java/com/amadeus/Params.java index e08c689a..1d26313d 100644 --- a/src/main/java/com/amadeus/Params.java +++ b/src/main/java/com/amadeus/Params.java @@ -3,6 +3,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -48,7 +49,12 @@ public static Params with(@NonNull String key, Object value) { * @return the Param object, allowing for convenient chaining */ public Params and(@NonNull String key, Object value) { - put(key, String.valueOf(value)); + if (value instanceof List) { + @SuppressWarnings("unchecked") List values = (List) value; + put(key, String.join(",", values)); + } else { + put(key, String.valueOf(value)); + } return this; } diff --git a/src/test/java/com/amadeus/ParamsTest.java b/src/test/java/com/amadeus/ParamsTest.java index 8ec29cb8..f2b76e91 100644 --- a/src/test/java/com/amadeus/ParamsTest.java +++ b/src/test/java/com/amadeus/ParamsTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.Arrays; import org.junit.jupiter.api.Test; public class ParamsTest { @@ -22,6 +23,11 @@ public class ParamsTest { assertEquals(params.toQueryString(), "bar=234&foo=123"); } + @Test public void testToQueryStringWithList() { + Params params = Params.with("foo", Arrays.asList("id1", "id2")); + assertEquals(params.toQueryString(), "foo=id1%2Cid2"); + } + @Test public void testToQueryStringWithEncodingError() { Params params = Params.with("foo", "123"); params.encoding = "foobar";