Skip to content

Instantly share code, notes, and snippets.

@tues
Created December 13, 2016 10:35
Show Gist options
  • Save tues/c3147252904cdb8ae3f7e8ace3df27da to your computer and use it in GitHub Desktop.
Save tues/c3147252904cdb8ae3f7e8ace3df27da to your computer and use it in GitHub Desktop.
Play JSON Option[String] deserializer
implicit object OptionalStringReads extends Reads[Option[String]] {
def reads(json: JsValue) = json match {
case JsString(s) => JsSuccess(Some(s))
case JsNull => JsSuccess(None)
case _ => JsError("error.expected.jsstring")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment