Introduce Configuration for `BigDecimal` representation.
We now allow configuring the default representation for BigDecimal and BigInteger values, still defaulting to string. BigDecimal can be configured to use Decimal128 by default.
Closes: #3444
Original pull request: #4916
pull/4921/head
Christoph Strobl10 months agocommitted byMark Paluch
@ -154,11 +161,18 @@ public class MongoCustomConversions extends org.springframework.data.convert.Cus
@@ -154,11 +161,18 @@ public class MongoCustomConversions extends org.springframework.data.convert.Cus
@ -298,6 +312,11 @@ public class MongoCustomConversions extends org.springframework.data.convert.Cus
@@ -298,6 +312,11 @@ public class MongoCustomConversions extends org.springframework.data.convert.Cus
returnuseNativeDriverJavaTimeCodecs(false);
}
// TODO: might just be a flag like the time codec?
@ -347,15 +366,24 @@ public class MongoCustomConversions extends org.springframework.data.convert.Cus
@@ -347,15 +366,24 @@ public class MongoCustomConversions extends org.springframework.data.convert.Cus
@ -103,3 +103,11 @@ class MyMongoConfiguration extends AbstractMongoClientConfiguration {
@@ -103,3 +103,11 @@ class MyMongoConfiguration extends AbstractMongoClientConfiguration {
}
}
----
[[mongo.numeric-conversion]]
== Big Number Format
MongoDB in its early days did not have support for large numeric values such as `BigDecimal`.
In order to persist values those types got converted into their `String` representation.
Nowadays `org.bson.types.Decimal128` offers a native solution to storing big numbers.
Next to influencing the to be stored numeric representation via the `@Field` annotation you can configure `MongoCustomConversions` to use `Decimal128` instead of `String` via the `MongoConverterConfigurationAdapter#numericFormat(...)` or set the `mongo.numeric.format=decimal128` property.