sksamuel / avro4s

Avro schema generation and serialization / deserialization for Scala
Apache License 2.0
719 stars 237 forks source link

No support for optional eithers #768

Closed GijsbertvanVliet closed 1 year ago

GijsbertvanVliet commented 1 year ago

This is an issue regarding the scala3 version of avro4s, but I don't seem to be able to add the required label to this issue for some reason. I'm trying to decode an avro event which has a field of type:

{
  "name": "...",
  "type":[
    "null",
    "string",
    "int"
  ]
}

In scala terms this would adheres to data type Option[Either[String, Int]]. Unfortunately the OptionDecoder does not support this type since it requires the number of types in the union schema to be equal to 2. The OptionDecoder does get an EitherDecoder in its constructor argument though, so in theory it should be able to decode the either if it's given I think.

altrack commented 1 year ago

Check the Mappings docs. I don't think there is a such thing in Mappings as Option of Either. Union of 3 types is rather a Shapeless or a Sealed Trait of Classes.

GijsbertvanVliet commented 1 year ago

Ok fair enough. But would you agree that the avro type UNION<null,A,B> could correspond to scala type Option[Either[A,B]] and similarly UNION<null,A,B,C> could correspond to Option[A :+: B :+: C :+: CNil]? If yes, then I could try to create a PR to support these build in type mappings.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.