Created
February 5, 2016 10:21
-
-
Save alchi/f2df9ed47336627171b9 to your computer and use it in GitHub Desktop.
play 2 result object sample
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
| 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