Closed fugithub79 closed 3 years ago
Hi @fugithub79
I don't know if this is an actual issue or should this be actually supported but have you tried to use the @AvroDefault annotation? Or on my current project this works or a "generator" does something like this ->
@AvroDefault(Avro.NULL)
val maybe: Sting? = null
Should work as @kossi has written. Closing this issue.
I tried to get the "default": null
in my schema, however it seems like I'm missing something?
@Serializable
data class Test(
@AvroDefault(Avro.NULL)
val nullable: String? = null
)
val record = Avro.default.schema(
serializer = Test.serializer()
)
println(record)
yields
{"type":"record","name":"Test","namespace":"com.test.avro","fields":[{"name":"nullable","type":["null","string"]}]}
How can I get
{"type":"record","name":"Test","namespace":"com.test.avro","fields":[{"name":"nullable","type":["null","string"], "default": null}]}
I use avro4k with AWS MSK+Glue schema registry with auto registration of new schemas, and schema compatibility fails since Glue complains about new nullable fields without a default value.
Thanks
edit. Wrong AvroDefault import :facepalm:
I want to generate a schema file. Given fields like the following
I would like to add "default": null to each of these in the generated schema. Unfortunately, it appears that I can't do something like:
Because the parser considers this to be invalid.
Is this an actual issue? Short of writing my own serializer, is there another way to accomplish the same thing?