Created
February 16, 2016 06:05
-
-
Save hoangong/e1840333aa6112f4f4f9 to your computer and use it in GitHub Desktop.
Play2 Json custom datatype serialization
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
val uuidReads = Reads[UUID](i => i match { | |
case s: JsString => { | |
JsSuccess(UUID.fromString(s.value)) | |
} | |
case _ => { | |
JsError("error") | |
} | |
}) | |
val uuidWrites = Writes[UUID](i => JsString(i.toString)) | |
implicit val uuidFormat: Format[UUID] = Format(uuidReads, uuidWrites) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment