Skip to content

Instantly share code, notes, and snippets.

@inmyth
Created June 12, 2018 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inmyth/3eb0470cc065ce0f4d40bd42204b9423 to your computer and use it in GitHub Desktop.
Save inmyth/3eb0470cc065ce0f4d40bd42204b9423 to your computer and use it in GitHub Desktop.
Scala Play Enum Id to Json Reads & Writes
object OkexStatus extends Enumeration {
type OkexStatus = Value
val filled = Value(1)
val unfilled = Value(0)
implicit val enumFormat = new Format[OkexStatus] {
override def reads(json: JsValue): JsResult[OkexStatus] = json.validate[Int].map(OkexStatus(_))
override def writes(enum: OkexStatus) = JsNumber(enum.id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment