avro-kotlin / avro4k

Avro format support for Kotlin
Apache License 2.0
198 stars 37 forks source link

Don't provide default decimal precision & scale #229

Closed Chuckame closed 4 months ago

Chuckame commented 4 months ago

Is your feature request related to a problem? Please describe. Currently, there is a default scale & precision. Those attributes are highly dependant to the usage.

Describe the solution you'd like Just no default. The user must provide its own scale & precision. This impacts the current AvroDecimal annotation, where we should remove the default precision, and set the default scale to 0 line the standard library.

The global default may be provided through a serializer or the avro config, but I would say to first not do it for simplicity.

Breaking change: annotating a BigDecimal with @Contextual or @Serializable(with = BigDecimalSerializer::class) will still need @AvroDecimal. We may want to provide a default configuration-less usage for a better adoption and simplicity with a default to the string type (no logical type), but this complicates the API to go back to a bytes or fixed type.

Whatever the default, there is 3 decimal types : bytes, fixed, and string (this one without the logical type).

Side note: there is an ongoing dev that would ship in avro 1.11.4 and 1.12.0 including a new big-decimal logical type where we don't need to provide a scale or a precision, which would fit perfectly to the need of a default configuration-less encoding of a BigDecimal

Chuckame commented 4 months ago

Released in v2.0.0