Reputation: 4840
I'm following along the Play! 2.1 coast-to-coast tutorial at http://mandubian.com/2013/01/13/JSON-Coast-to-Coast/ but cannot get even the most trivial example working.
When I compile my project I get an error:
could not find implicit value for parameter reducer: play.api.libs.functional.Reducer[play.api.libs.json.JsString,B]
My controller code is as follows:
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._
object MyController extends Controller{
val validate = (
(__ \ 'title).json.pick[JsString] and
(__ \ 'desc).json.pick[JsString]
).reduce
def test() = Action { implicit request =>
Ok("test")
}
}
What am I missing to get this working?
Upvotes: 1
Views: 779
Reputation: 4840
The syntax here is not quite right. 'pick' returns a JsValue (the Play! equivalent of valid Json types including String, Array, etc).
To validate multiple json fields you need to use 'pickBranch' which returns a JsObject (which is basically the equivalent of a Map[String, JsValue]). I'm guessing that reduce is a merge operation for several JsObjects.
I actually still haven't found a good use case for 'pick'. The '\' syntax seems to do the equivalent job with less code and clutter.
Upvotes: 0