I am using Jersey client 2.25.1 and the queryParam(...) method does not correctly encode the values, e.g this approach fails:
Response response = client.target(uri)
.queryParam("a", "%20") // Translated into space ' '(!)
.queryParam("b", "{") // Will ruin template parsing(!)
.queryParam("c", "}") // Will ruin template parsing(!)
.queryParam("d", URLEncoder.encode(" ", "UTF-8")) // Using explicit encoding will translate ' ' into '+'(!)
.request().get();
So the workaround suggested is like this:
Response response = client.target(uri)
.queryParam("a", "{a}").resolveTemplate("a", "%20")
.queryParam("b", "{b}").resolveTemplate("b", "{")
.queryParam("c", "{c}").resolveTemplate("c", "}")
.queryParam("d", "{d}").resolveTemplate("d", " ")
.request().get();
This works, but it puzzles me that this very common use case doesn't have better library support from the Jersey client(?) I want to be able to have an arbitrary value properly URL encoded as a query parameter, so that exact same value will reach the server side.
Are there alternatives to this solution? Which is the preferred/best way to solve this?