I run through the JSON documentation at http://www.playframework.com/documentation/2.2.x/ScalaJsonRequests but didn't find what I needed. What I need is make my class being able to be converted to JSON like this:
# model
case class MyClass(a: Int, b: String ....)
# controller
def myAction = Action {
val myClass = getMyClass()
Ok(toJson(myClass))
}
So wherever I call Ok(toJson(myClass))
, it converts to JSON by itself. How can I do this?
P.S. Sorry, I forgot to mention MyClass has java.util.UUID
as an Id
and some other class as a field:
case class MyClass(id: UUID, a: Int, b: String, c: MyClass2 ....)
So Json.writes[MyClass]
doesn't work at least because of UUID
.