I have a class which I want to be able to convert to json:
case class Page[T](items: Seq[T], pageIndex: Int, pageSize: Int, totalCount: Long)
object Page {
i
maybe you can write something like:
case class Page(items: JsValue, pageIndex: Int, pageSize: Int, totalCount: Long)
Put the JsValue instead of the Seq[T]
here is my code example:
case class ResponseObject(state:Int = 1,data:JsValue)
case class City(id:Int,name:String,sort:String){
require(id > 0)
}
def list = Action {
implicit val cityFormat:Format[City] = Json.format[City]
implicit val responseFormat=Json.format[ResponseObject]
Ok(Json.toJson(ResponseObject(data=Json.toJson(City.list)))).as("application/json")
}