Skip to content

Instantly share code, notes, and snippets.

@anuragsrivastava06
Last active April 15, 2018 09:45
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 anuragsrivastava06/d5792305a56730e33f2be5d841ecc368 to your computer and use it in GitHub Desktop.
Save anuragsrivastava06/d5792305a56730e33f2be5d841ecc368 to your computer and use it in GitHub Desktop.
implicit def optionWriter[A]
(implicit writer: JsonWriter[A]): JsonWriter[Option[A]] =
new JsonWriter[Option[A]] {
def write(option: Option[A]): Json =
option match {
case Some(aValue) => writer.write(aValue)
case None => JsNull
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment