I am using Avro4s. It's easy to serialise a
Map[String, T]
but I have a situation like
sealed trait Base
case object First extends Base
case object Second extends Base
and I need to serialise something like
Map[Base, T]
Any advice on the best way to achieve this? Thanks.
The thing is that according to the Avro spec
So the only type supported by Avro is
Map[String,T]
. It means that you need to write some custom code that will map yourMap[Base, T]
ontoMap[String,T]
and back. Something like this will probably work for you:Usage example:
and the output is something like: