Skip to content

Instantly share code, notes, and snippets.

@farmdawgnation
Created January 4, 2018 16:46
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 farmdawgnation/0a61e79bdcd25ccddf2b9fb1ff8e330b to your computer and use it in GitHub Desktop.
Save farmdawgnation/0a61e79bdcd25ccddf2b9fb1ff8e330b to your computer and use it in GitHub Desktop.
object MyResponseSerializer extends Serializer[Response] {
val clazz = classOf[Product]
override def deserialize(implicit formats: Formats): PartialFunction[(TypeInfo, JValue), Response] = {
case (TypeInfo(`clazz`, _), serializedProduct) =>
(serializedProduct \ "data") match {
case JArray(fields) =>
val datas = fields.map(_.extract[Data])
Response(datas)
case _ =>
throw new RuntimeException("Response doesn't have data")
}
}
override def serialize(implicit formats: Formats): PartialFunction[Any, JValue] = {
case resp: Response =>
decompose(resp)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment