Skip to content

Instantly share code, notes, and snippets.

@alchi
Created February 5, 2016 10:21
Show Gist options
  • Select an option

  • Save alchi/f2df9ed47336627171b9 to your computer and use it in GitHub Desktop.

Select an option

Save alchi/f2df9ed47336627171b9 to your computer and use it in GitHub Desktop.
play 2 result object sample
package entities
import helpers.HttpStatus
import play.api.libs.json._
final case class ResultObject(data: Any = null, message: String = "", statusCode: Int = HttpStatus.OK, timestamp: Long = System.currentTimeMillis() / 1000L)
object ResultObject {
implicit object ResultFormat extends Format[ResultObject] {
def writes(entry: ResultObject): JsValue = JsObject(Seq(
"code" -> JsNumber(entry.statusCode),
"message" -> JsString(entry.message),
"timestamp" -> JsNumber(entry.timestamp),
"data" -> format(entry.data))
)
def reads(json: JsValue): JsResult[ResultObject] = {
JsSuccess(new ResultObject)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment