playframework/playframework — pull request #1860 by dwhjames (2013-10-19 20:59:03+00:00)
Title: Introduce BodyParsers.parse.json(Reads[A])

This pull request introduces a BodyParser that not only validates the content type as Json and parses the body to a `JsValue`, but then goes on the validate the `JsValue` according to the implicit `Reads[A]`.

While `BodyParser.validate` can achieve something similar (from the docs),

```scala
def validateJson[A : Reads] = parse.json.validate(
_.validate[A].asEither.left.map(e => BadRequest(JsError.toFlatJson(e)))
)
```

the function parameter to `BodyParser.validate[B](f: A => Either[SimpleResult, B])` means that one can’t use `Future` and thus can’t invoke `GlobalSettings.onBadRequest`.

`BodyParsers.parse.json(Reads[A])` makes use of the private helper method `BodyParsers.parse.createBadResult` to produce a response in the case of Json validation error.