Skip to content
Snippets Groups Projects
Unverified Commit a4158f13 authored by lbrdnk's avatar lbrdnk Committed by GitHub
Browse files

[Mongo] Convert bson Decimal128 negative zero to BigInteger zero (#44611)

* Convert bson Decimal128 negative zero to BigInteger zero
parent 692841e0
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,11 @@
org.bson.types.Decimal128
(from-document [^org.bson.types.Decimal128 input _opts]
(.bigDecimalValue input))
;; As per https://mongodb.github.io/mongo-java-driver/5.1/apidocs/bson/org/bson/types/Decimal128.html#bigDecimalValue()
;; org.bson.types.Decimal128/POSITIVE_ZERO is convertible to big decimal.
(if (.equals input org.bson.types.Decimal128/NEGATIVE_ZERO)
0M
(.bigDecimalValue input)))
java.util.List
(from-document [^java.util.List input opts]
......
......@@ -26,3 +26,14 @@
(-> mseqk mongo.conversion/to-document (mongo.conversion/from-document {:keywordize true}))))
(is (= mseqs
(-> mseqs mongo.conversion/to-document (mongo.conversion/from-document nil))))))))
(deftest bson-negative-zero->big-decimal-test
(testing "Bson Decimal128 zero is converted to BigDecimal zero"
(is (= {"negativeZero" 0M}
(mongo.conversion/from-document
(org.bson.Document. "negativeZero" org.bson.types.Decimal128/NEGATIVE_ZERO)
nil)))
(is (= {"positiveZero" 0M}
(mongo.conversion/from-document
(org.bson.Document. "positiveZero" org.bson.types.Decimal128/POSITIVE_ZERO)
nil)))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment