Created
March 9, 2014 16:24
-
-
Save kouphax/9450253 to your computer and use it in GitHub Desktop.
Some JSON magic in Play.
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 | |
import play.api._ | |
import play.api.mvc._ | |
import play.api.libs.json._ | |
import play.api.libs.functional.syntax._ | |
object Application extends Controller { | |
implicit val jsonifier = ( | |
(__ \ "id").format[Int] and | |
(__ \ "name").format[String] | |
)(Shannon.apply, unlift(Shannon.unapply)) | |
case class Shannon(val id: Int, val name: String) | |
def index = Action { | |
val json = """[{"id":1,"name":"james"},{"id":2,"name":"shannon"}]""" | |
val list = Json.fromJson[List[Shannon]](Json.parse(json)) | |
Ok(Json.toJson(list.get)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment