Created
June 12, 2018 07:23
-
-
Save inmyth/3eb0470cc065ce0f4d40bd42204b9423 to your computer and use it in GitHub Desktop.
Scala Play Enum Id to Json Reads & Writes
This file contains 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
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