This project served to demonstrate the playframework JSON API in Java and in Scala.
It was used at the Berlin User Group.
-
build JSON with Java
-
build JSON with Scala
-
consume JSON (request body) with Java
in java:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Json.setObjectMapper(mapper);
(not needed anymore in trunk: playframework/playframework#3670)
- consume JSON (request body) with Scala
- validate id != -1 with
(.filter(_ != -1))
- show with optional field with
Option[String]
- defined default reads and writes
- defined reads and writes in one time (with Formats)
-
send and consume JSON with WS in Java
-
send and consume JSON with WS in Scala
-
consume and transform JSON in Scala
val copyValue: Reads[JsObject] = (
(__ \ "id").json.prune and
(__ \ "name").json.copyFrom( (__ \ "group").json.pick )
).reduce
val addValue: Reads[JsObject] = (
(__ \ "id").json.prune and
(__ \ "group").json.pickBranch and
(__ \ "myfield").json.put(JsNumber(42))
).reduce