Thanks a lot for this. It's amazing work what you're doing with the API, it was exactly what I was searching for :)
I have a slight problem getting the validate.fold example working however as I have it wrapped by Async as required by Reactive Mongo.
e.g.
def create = Action(parse.json) { request =>
Async {
val json = request.body
json.validate[User].fold(
valid = (res =>
collection.insert[JsValue](res).map(lastError =>
Ok("Mongo LastError:%s".format(lastError)))
),
invalid = ( e => BadRequest(e.toString) )
)
}
}
Provides the error on the last line (invalid = ..):
"type mismatch; found : play.api.mvc.SimpleResult[String] required:
scala.concurrent.Future[play.api.mvc.Result]"
Is there a way to provide a Future of a BadRequest?
Also, for my userReads implicit val, I had to specify "(User.apply _)" e.g.
implicit val userReads = (
(__ \ "email").read[String] and
(__ \ "firstName").read[String] and
(__ \ "lastName").read[String]
)(User.apply _)
And if I change it to just have (User) at the end, as suggested it spurts out the following:
"- overloaded method value apply with alternatives: [B](f: B => (java.lang.String, java.lang.String, String))(implicit fu:
play.api.libs.json.util.ContravariantFunctor[play.api.libs.json.Reads])play.api.libs.json.Reads[B] <and> [B](f: (java.lang.String, java.lang.String, String) => B)(implicit fu:
play.api.libs.json.util.Functor[play.api.libs.json.Reads])play.api.libs.json.Reads[B] cannot be applied to (models.User.type)"
(I have declared the implicit val inside the User object, as there was not a complete example and I figured it didn't belong in the Controller).