Question

I was wondering what query parameter delimiter is the Java play framework expecting.

I retrieve my query parameters in my action method like so:

Map<String, String[]> qMap = request().queryString();

I expect a list of doubles in one of the parameters, so I extract them like so:

double lat = Double.parseDouble(qMap.get("point")[0]);
double lon = Double.parseDouble(qMap.get("point")[1]);

I expected I could pass these parameters with the following query:

?point=2,3

But this rendered a NumberFormatException:

Caused by: java.lang.NumberFormatException: For input string: "2,3"

So how can I pass an array of values for a single query parameter?

Was it helpful?

Solution

To pass multiple values for the same query string variable construct a query string like this:

?point=2&point=3

That will give you a query string map like so:

{ point = [ "2", "3" ] }

That said, you may also consider using two separate parameter names:

?lat=2&lon=3

... resulting in:

{ lat = [ 2 ], lon = [ 3 ] }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top