This file contains hidden or 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
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 => Cbor.encode(x).toByteArray | |
case _ => | |
throw new RuntimeException(s"does not support encoding of $o") | |
} |
This file contains hidden or 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
akka.actor { | |
serializers { | |
borer-cbor = "com.example.borer.cbor.BorerAkkaSerializer" | |
} | |
serialization-bindings { | |
"com.example.borer.serializable.BorerSerializable" = borer-cbor | |
} | |
} |
This file contains hidden or 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
sealed trait Zoo extends BorerSerializable { | |
def primaryAttraction: Animal | |
} | |
object Zoo { | |
final case class NorthZoo(primaryAttraction: Animal) extends Zoo | |
final case class SouthZoo(primaryAttraction: Animal) extends Zoo | |
} |
This file contains hidden or 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
class BorerAkkaSerializer extends CborAkkaSerializer[BorerSerializable] with Codecs { | |
override def identifier: Int = 19923 | |
register[Zoo] | |
register[Park] | |
register[Theatre] | |
} |
This file contains hidden or 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
trait CborAkkaSerializer[Ser] extends Serializer { | |
private var registrations: List[(Class[_], Codec[_])] = Nil | |
protected def register[T <: Ser: Encoder: Decoder: ClassTag]: Unit = { | |
registrations ::= scala.reflect.classTag[T].runtimeClass -> Codec.of[T] | |
} | |
override def includeManifest: Boolean = true |
This file contains hidden or 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
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 => Cbor.encode(x).toByteArray | |
case x: Park => Cbor.encode(x).toByteArray | |
case x: Theatre => Cbor.encode(x).toByteArray | |
case _ => |
This file contains hidden or 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
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") | |
} |
This file contains hidden or 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
trait JacksonSerializable | |
final case class Zoo(primaryAttraction: Animal) extends JacksonSerializable | |
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") | |
@JsonSubTypes( | |
Array( | |
new JsonSubTypes.Type(value = classOf[Lion], name = "lion"), | |
new JsonSubTypes.Type(value = classOf[Elephant], name = "elephant") | |
) |
This file contains hidden or 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
akka.actor { | |
serializers { | |
borer-json = "com.example.borer.json.BorerAkkaSerializer" | |
} | |
serialization-bindings { | |
"com.example.borer.serializable.BorerSerializable" = borer-json | |
} | |
} |
This file contains hidden or 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
import io.bullet.borer.Codec | |
import io.bullet.borer.derivation.MapBasedCodecs.{deriveAllCodecs, deriveCodec} | |
trait Codecs { | |
implicit lazy val animalCodec: Codec[Animal] = deriveAllCodecs | |
implicit lazy val zooCodec: Codec[Zoo] = deriveCodec | |
} |
NewerOlder