Created
December 11, 2016 21:28
-
-
Save applethepeanut/1f3c0c9d3cb495da7d4756f1df9ad7c1 to your computer and use it in GitHub Desktop.
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
case class Blah(id: String, name: String) | |
object Blah { | |
implicit val jsonFormats = new RootJsonFormat[Blah] { | |
override def read(json: JsValue): Blah = { | |
val js = json.asJsObject | |
(js.fields("some_id"), js.fields("some_name")) match { | |
case (JsString(id), JsString(name)) => Blah(id, name) | |
case _ => deserializationError(s"Failed to read `Blah` from json `$json`") | |
} | |
} | |
override def write(blah: Blah): JsValue = JsObject( | |
"id" -> JsString(blah.id), | |
"name" -> JsString(blah.name) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment