BigDecimal serialization with unknown scale and precision

383 Views Asked by At

I am trying to serialize a data class using Avro4k.

@Serializable
class Aggregator(
    @ScalePrecision(10, 10)
    @Serializable(with = BigDecimalSerializer::class)
    val value: BigDecimal
)

The problem is that I don't know the scale and precision of the BigDecimal beforehand, and I get rounding errors if they are not big enough.

Is there a way to not inform the scale and precision, and use whatever values the provided object have? I don't know if Avro / Avro4k would support that.

0

There are 0 best solutions below