Skip to content

Commit

Permalink
Merge pull request #257 from Sprokof/params-accept-array-string
Browse files Browse the repository at this point in the history
Params accept array string
  • Loading branch information
tsolakoua authored Mar 8, 2024
2 parents 68a3c58 + f49c3bf commit e6c611d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/java/com/amadeus/Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> values = (List<String>) value;
put(key, String.join(",", values));
} else {
put(key, String.valueOf(value));
}
return this;
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/amadeus/ParamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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";
Expand Down

0 comments on commit e6c611d

Please sign in to comment.