Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>EDIT2</h2> <p>New <a href="http://www.playframework.com/documentation/2.1.x/ScalaJsonRequests" rel="nofollow">Wiki link</a> for v2.1. The old link below is not working anymore.</p> <h2>EDIT</h2> <p>We'll all be happy to read the new Wiki entry for this point. Check <a href="https://github.com/playframework/Play20/wiki/Scalajson" rel="nofollow">this</a> out</p> <hr> <h2>PREVIOUS</h2> <p>Here is the comment from the community about the state of Json support in play 2.0. <a href="https://groups.google.com/d/msg/play-framework/VeVacV4CU1o/Zm5gzwF7PScJ" rel="nofollow">link to Post</a></p> <p>They are moving from Jackson to a philosophy inspired by <a href="http://debasishg.blogspot.com/2010/07/sjson-now-offers-type-class-based-json.html" rel="nofollow">SJSON</a> 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...)</p> <p>So here is what you can read on the post:</p> <pre><code>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" -&gt; JsString(p.blah))) } def act = Action { implicit request =&gt; // 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)) } </code></pre> <p>In the second link (<a href="http://debasishg.blogspot.com/2010/07/sjson-now-offers-type-class-based-json.html" rel="nofollow">SJSON</a>), I propose you to pay special attention to the generic formatting possible by using <code>case class</code> and their deconstruction method (<code>unapply</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload