Open PhilippZugColenet opened 2 months ago
Hey,
Thanks for reaching us about this bug. I've just checked it, and surprisingly it fails. I'm currently trying to fix it!
It's more complex than expected. The main issue is that Avro4k (especially kotlinx-serialization) is not able to retrieve the default value for optional kotlin fields, that's why it has been created an @AvroDefault
annotation.
To fix it, I would need to use the writer schema for reading, then adapting the writer schema to the reader schema/data class. This could be ok to do, but requires a lot of code.
Currently, a v2 of avro4k is in progress fixing a lot of stuff, improving performances and the Avro
entrypoint has been totally revamped for better and simpler usability.
I will take this feature into account. Until that moment, please provide the default value through the @AvroDefault
. Sorry for this workaround, and thanks for your comprehension!
Hello,
when I try to deserialize an Avro message from a JSON that is missing an optional field - with default null - the I got an AvroTypeException.
Used Avro4k 1.10.1
Given the following Avro Schema:
the following data.json:
and the following data class
I got this exception:
org.apache.avro.AvroTypeException: Expected field name not found: optionalString
.Kotlin Test-Code to reproduce (data.json contains the data like above):
I my opinion this is a bug and I would expect it to accept a message where an optional field is missing since it has a default value.
Or did I do something wrong? Can you help me please?