Created
January 4, 2018 16:46
-
-
Save farmdawgnation/0a61e79bdcd25ccddf2b9fb1ff8e330b 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
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