Skip to content

Instantly share code, notes, and snippets.

@skvithalani
Last active February 25, 2020 11:48
Show Gist options
  • Save skvithalani/cadc6fa890961256aacfb93e00f697b9 to your computer and use it in GitHub Desktop.
Save skvithalani/cadc6fa890961256aacfb93e00f697b9 to your computer and use it in GitHub Desktop.
class BorerAkkaSerializer() extends Serializer with Codecs {
override def identifier: Int = 19923
override def includeManifest: Boolean = true
override def toBinary(o: AnyRef): Array[Byte] = o match {
case x: Zoo => Json.encode(x).toByteArray
case _ =>
throw new RuntimeException(s"does not support encoding of $o")
}
override def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef = {
if (classOf[Zoo].isAssignableFrom(manifest.get))
Json.decode(bytes).to[Zoo].value
else
throw new RuntimeException(s"does not support decoding of ${manifest.get}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment