Closed williamboxhall closed 3 years ago
I tried to work around this with @org.apache.avro.reflect.Union
but it didn't help
As mentioned in https://github.com/avro-kotlin/avro4k/issues/101#issuecomment-890573467 @thake says OPEN polymorphic references aren't supported in Avro4k. @thake are there any plans to change this? Can you think of a workaround for this short of making this sealed (sadly not a great option in our codebase)
It is planned to support this feature. It should not be too hard to implement. @williamboxhall If you want to give it a try, I will be very happy to review a PR for this feature.
Thanks @thake that's a fair call. I'm not sure if I'll be able to absorb getting up to speed in avro4ks internals and then doing this PR while dealing with our internal deadlines, but I will definitely try :).
In the meantime, our workaround is probably to just use properly sealed classes, which causes some other significant compromises but gives us a path forward.
I've taken a stab at making a PR for this: https://github.com/avro-kotlin/avro4k/pull/109
Implemented with #110
According to the kotlinx serialization docs it should be possible to register the subtypes of an abstract class as part of the
serializerModule
. However, it doesn't seem to work:As you can see, I also naively tried adding both
@Polymorphic
and@Contextual
and@file:UseContextualSerialization
clutching at straws that they'D offer the hints necessary for Avro4K to treat this asSerialKind.CONTEXTUAL
instead ofSerialKind.OPEN
, to no available. I suspect that Avro4K might need to introduce a newSerialKind.POLYMORPHIC
or something like that, to match what's in kotlinx serialization.