1

I'm looking for a Spring or Apache solution that separates multiple query parameters with a piped character. I'll even take a library that reduces an array or collection of strings into a single string that is separated with a piped character.

MultiValueMap<String, String> multiValueMap = new HttpHeaders();
multiValueMap.put("arg1", new List<String>(){{
    add("foo");
    add("bar");
}});

URIBuilder uriBuilder = URIBuilder.fromUri("foo.com");
uriBuilder.queryParams( queryArguments );

RestTemplate restTemplate = new RestTemplate();
String lazyResponse = restTemplate.getForObject(uriBuilder.build(), String.class )

Otherwise I'm left with making a wheel.

public String makeHttpParameter(List<String> args, char seperator){
    Iterator<String> iterator = args.iterator();
    StringBuilder builder = new StringBuilder();

    while( iterator.hasNext() ){
        builder.append(iterator.next());
        if(iterator.hasNext()){
            builder.append(seperator);
        }
    }
    return builder.toString();
}
Dan
  • 1,179
  • 2
  • 10
  • 18

0 Answers0