Do you know of any utility class/library, that can convert Map into URL-friendly query string?
Example:
I have a map:
\"param1\"=12,
\"param2
This is the solution I implemented, using Java 8 and org.apache.http.client.URLEncodedUtils
. It maps the entries of the map into a list of BasicNameValuePair
and then uses Apache's URLEncodedUtils
to turn that into a query string.
List nameValuePairs = params.entrySet().stream()
.map(entry -> new BasicNameValuePair(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
URLEncodedUtils.format(nameValuePairs, Charset.forName("UTF-8"));