Created
May 25, 2012 11:14
-
-
Save tototoshi/2787381 to your computer and use it in GitHub Desktop.
productFormatあるよ!
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
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