avro4k icon indicating copy to clipboard operation
avro4k copied to clipboard

Add support for using defaut values

Open asmadsen opened this issue 4 years ago • 2 comments

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

asmadsen avatar Feb 22 '22 14:02 asmadsen

I think it should be configurable

Chuckame avatar Aug 08 '22 12:08 Chuckame

@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 avatar Aug 12 '22 11:08 thake

Closed because of no active discussion

thake avatar Apr 18 '23 20:04 thake