Skip to content

Instantly share code, notes, and snippets.

@hoangong
Created February 16, 2016 06:05
Show Gist options
  • Save hoangong/e1840333aa6112f4f4f9 to your computer and use it in GitHub Desktop.
Save hoangong/e1840333aa6112f4f4f9 to your computer and use it in GitHub Desktop.
Play2 Json custom datatype serialization
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