avro-kotlin / avro4k

Avro format support for Kotlin
Apache License 2.0
188 stars 36 forks source link

DO NOT MERGE: Demonstrate failure when subclass is sealed #112

Closed williamboxhall closed 2 years ago

williamboxhall commented 2 years ago

@thake I didn't know the easiest way to get this in front of you, but extending on our work there appears to be an important edgecase that isn't covered. Try running PolymorphicClassSchemaTest in this branch.

For some reason it's not capturing the kClass inside of the descriptor for SealedChildTwo - but I have no idea why:

Contextual or default serializer not found for kotlinx.serialization.Sealed<SealedChildTwo>(com.github.avrokotlin.avro4k.schema.UnsealedChildTwo: com.github.avrokotlin.avro4k.schema.UnsealedChildTwo)
java.lang.IllegalArgumentException: Contextual or default serializer not found for kotlinx.serialization.Sealed<SealedChildTwo>(com.github.avrokotlin.avro4k.schema.UnsealedChildTwo: com.github.avrokotlin.avro4k.schema.UnsealedChildTwo)
    at com.github.avrokotlin.avro4k.schema.SchemaForKt.schemaFor(SchemaFor.kt:189)
    at com.github.avrokotlin.avro4k.schema.ClassSchemaFor.buildField(ClassSchemaFor.kt:78)
    at com.github.avrokotlin.avro4k.schema.ClassSchemaFor.dataClassSchema(ClassSchemaFor.kt:63)
    at com.github.avrokotlin.avro4k.schema.ClassSchemaFor.schema(ClassSchemaFor.kt:43)
    at com.github.avrokotlin.avro4k.schema.UnionSchemaFor.schema(UnionSchemaFor.kt:19)
    at com.github.avrokotlin.avro4k.Avro.schema(Avro.kt:264)
    at com.github.avrokotlin.avro4k.Avro.schema(Avro.kt:269)
    at com.github.avrokotlin.avro4k.schema.PolymorphicClassSchemaTest$1$1.invokeSuspend(PolymorphicClassSchemaTest.kt:38)
thake commented 2 years ago

This should be addressed with #111

williamboxhall commented 2 years ago

Oh that's a relief @thake I'll take a look! I just pushed up an extremely ugly and hacky workaround for this but I'm sure yours is a lot better.