EDIT2
New Wiki link for v2.1. The old link below is not working anymore.
EDIT
We'll all be happy to read the new Wiki entry for this point. Check this out
PREVIOUS
Here is the comment from the community about the state of Json support in play 2.0.
link to Post
They are moving from Jackson to a philosophy inspired by SJSON that offers more control on the un/marshalling, that brings facilities to manage them, w/o the overhead of Reflection (which I agree with them is a pain for performance and is fragile against Class changes...)
So here is what you can read on the post:
case class Blah(blah: String)
// if you want to directly serialize/deserialize, you need to write yourself a formatter right now
implicit object BlahFormat extends Format[Blah] {
def reads(json: JsValue): Blah = Blah((json \ "blah").as[String])
def writes(p: Blah): JsValue = JsObject(List("blah" -> JsString(p.blah)))
}
def act = Action { implicit request =>
// to get a Blah object from request content
val blah = Json.parse(request.body.asText.get).as[Blah]
// to return Blah as application/json, you just have to convert your Blah to a JsValue and give it to Ok()
Ok(toJson(blah))
}
In the second link (SJSON), I propose you to pay special attention to the generic formatting possible by using case class
and their deconstruction method (unapply
).