spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Deprecate `MongoCustomConversions.BigDecimalRepresentation.STRING`

Open mp911de opened this issue 9 months ago • 1 comments

For Spring Data MongoDB 5.0, we should deprecate MongoCustomConversions.BigDecimalRepresentation.STRING (not for removal) and switch the BigDecimal default to BigDecimalRepresentation.DECIMAL128 to indicate that Decimal128 is the preferred data type enabling range queries.

Storing big decimals as string is still a valid option, deprecation expresses that there are certain limitations and applications can use that option if they are aware of the implications.

Follow-up to #3444 and #4916

mp911de avatar Mar 11 '25 08:03 mp911de

Migrating default decimal format representation is a rather subtle change in terms of discoverability as it doesn't come with a behavior that incurs compiler warnings/errors, rather the database format is a different for queries and for the storage format itself.

For cases, where the value is stored as string, a save operation would convert the value to Decimal128. It might make sense to be rather strict in our default setup so that such cases fail fast by initially not registering StringToBigDecimal converters.

Users wanting a gradual migration could configure a mode where read converters (StringToBigDecimal) are registered for the reading case along with using the new Decimal128 default (BigDecimalRepresentation.DECIMAL128.lenient(), BigDecimalRepresentation.DECIMAL128.allowStringReads()). Our default would use a strict variant of BigDecimalRepresentation.DECIMAL128 or BigDecimalRepresentation.strictDecimal128() to improve expressivity.

mp911de avatar Jun 12 '25 14:06 mp911de