Reputation: 5792
I have to handle the following GET request in my Play application eg.
http://host/somemethod?queries[search]=asdf&perPage=100&sorts[name]=0
Now, normally GET requests like:
http://host/somemethod?queries=asdf&perPage=100&sorts=0
can be easily handled with eg.
GET /somemethod controllers.SomeMethodController.getPeople(queries:String ?= "", perPage: Int ?= 10, sorts:String ?= "")
but the params like: queries[search]=asdf
or sorts[name]=0
are not resolved properly
(tried simple String
type, Seq[String]
or Map[String,String]
- the last one throws exception about missing QueryStringBinder
)
How do I map those query params to a method parameters with Play routing? Do I need to create my own custom QueryStringBinder
?
Upvotes: 3
Views: 1515
Reputation: 1033
Your assumption is correct. Maps are not supported by the default QueryString binder and you therefor should implement your own QueryStringBindable
. The Javadoc of QueryStringBindable should give you a hint how to implement it.
Play 2.x supports the following query string parameter types:
See Binders.scala for all supported types.
Upvotes: 1