Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created May 25, 2012 11:14
Show Gist options
  • Save tototoshi/2787381 to your computer and use it in GitHub Desktop.
Save tototoshi/2787381 to your computer and use it in GitHub Desktop.
productFormatあるよ!
scala> import play.api.libs.json._
import play.api.libs.json._
scala> import play.api.libs.json.Generic._
import play.api.libs.json.Generic._
scala> case class User(id: Long, name: String, age: Int)
defined class User
scala> implicit def userFormat: Format[User] = productFormat3("id", "name", "age")(User.apply)(User.unapply)
userFormat: play.api.libs.json.Format[User]
scala> Json.toJson(User(1, "peter", 20))
res0: play.api.libs.json.JsValue = {"id":1,"name":"peter","age":20}
scala> Json.stringify(Json.toJson(User(1, "peter", 20)))
res1: String = {"id":1,"name":"peter","age":20}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment