My problems starts here with a limitation with HashMap in Java that does not allow using multiple values for same key. As in my code written below i need to have multiple values for k5 & k6
.
map is the main hashmap of QueryParameters that i will be passing on to be used in my RestAPI request. Approach tried: Created different Map of String and String[] type and then merge which i found would not be allowed to be merged.Code of the same has been marked as commented via //
My REST request looks like the following and i am finding it difficult how to send it in the following manner:
https://myURL/api&k1[]=value&k2=2value&k5[]=v3&k5[]=v4&k5[]=v5&k6[]=v7&k6[]=v8&k6[]=v8
If there is any other way to represent this in Java, please do let me know.
Map<String, String> map = new HashMap<>();
map.put("k1", "value");
map.put("k2", "2value");
//String[] k5 = new String[]{"v3", "v4", "v5"};
map.put("k5[]", "v3");
map.put("k5[]", "v4");
map.put("k5[]", "v5");
//String[] k6= new String[]{"v7", "v8", "v9"};
map.put("k6[]", "v7");
map.put("k6[]", "v8");
map.put("k6[]", "v9");
It pretty simple actually. Here's what you'll need to do:
If you want to add more elements to this, you can define the map as
Map<String, List<String>>