avro-kotlin / avro4k

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

Default value to null when the field is nullable #129

Closed Chuckame closed 1 year ago

Chuckame commented 1 year ago

Hey, great lib btw.

It should be cool to have the generated schema with default = null when the field is nullable without the needs of @Avro(NULL).

It helps a lot for compat thanks to default and reduces the amount of code just for default null value !

What do you think ?

thake commented 1 year ago

Thanks for your feedback. This seems to be a good addition to the library. Can you provide a PR?

To support this use case, a flag must be introduced in AvroConfiguration. It should be possible to override this configuration by explicitly stating that no default should be defined.

Chuckame commented 1 year ago

Oh wait... After the week-end, I started to find how to fix it.

But in fact, "defaultValue": null and no defaultValue is the same when we are on a nullable field (e.g. union with "null" type).

I'm closing it, sorry for the disturb.

Btw thanks for your quick answer !

EDIT: I checked all compatibility modes using avro's CompatibilityChecker#isCompatible method, and using AKHQ ui, all by reading the docs here.