Open
Description
The following codec results in an error:
import vulcan.Codec
import vulcan.generic.*
sealed trait S
case class A(i: Int) extends S
val c1: Codec[S] = Codec.derive
Codec.option(c1).schema // AvroError(org.apache.avro.AvroRuntimeException: Nested union: ["null",[{"type":"record","name":"A","namespace":"avrounion","fields":[{"name":"i","type":"int"}]}]])
However, what I would like is
implicit val optionalUnion: Codec[Option[S]] = {
import cats.implicits.catsSyntaxSemigroup
implicit val ca: Codec[A] = Codec.derive
Codec.union[Option[S]](alt =>
alt[None.type] |+| alt[Some[A]]
)
}
optionalUnion.schema
/*
[ "null", {
"type" : "record",
"name" : "A",
"namespace" : "avrounion",
"fields" : [ {
"name" : "i",
"type" : "int"
} ]
} ]
*/
Metadata
Metadata
Assignees
Labels
No labels