Created
February 12, 2014 17:29
-
-
Save josephpconley/8960352 to your computer and use it in GitHub Desktop.
Play controller serving nested case class as Json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
case class Root(id: Int, name: String, children: Seq[Child]) | |
case class Child(id: Int, name: String) | |
object Application extends Controller with Secured{ | |
def test = Action { implicit req => | |
//childFmt must go first, otherwise the rootFmt will not compile | |
implicit val childFmt = Json.writes[Child] | |
implicit val rootFmt = Json.writes[Root] | |
val children = Seq( | |
Child(1, "child1"), | |
Child(2, "child2"), | |
Child(3, "child3") | |
) | |
val root = Root(0, "root", children) | |
Ok(Json.toJson(root)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment