avro-kotlin / avro4k

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

Add support for using defaut values #126

Closed asmadsen closed 1 year ago

asmadsen commented 2 years ago

Add support for using defaut values in constructor if record does not contain field

Chuckame commented 1 year ago

I think it should be configurable

thake commented 1 year ago

@asmadsen, thanks for opening this PR!

While this change would improve usability with default values in kotlin, I think it conflicts with how Avro schemas should be read. Avro schemas already contain default values for optional fields. These default values are considered for encoding/decoding if the annotation @AvroDefault is used.

The @AvroDefault annotation was needed because we cannot access the kotlin native default values. If we consider the kotlin native default value when decoding values, we would not be consistent with the generated Avro schema because the kotlin native default value is not part of the Avro read schema.

Look at AvroDefaultValuesDecoderTest for more information on how to use Avro default values.

thake commented 1 year ago

Closed because of no active discussion