Skip to content

Commit

Permalink
fix: Double to BigDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzc19 authored and zigzago committed Oct 23, 2023
1 parent 19d1dbd commit 83542f2
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,19 +488,18 @@ internal class BsonModule(uuidRepresentation: UuidRepresentation? = null) : Simp
}

private object BigDecimalBsonDeserializer : JsonDeserializer<BigDecimal>() {

override fun deserialize(jp: JsonParser, ctxt: DeserializationContext): BigDecimal {
return if (jp.currentToken == VALUE_NUMBER_FLOAT) {
BigDecimal(jp.doubleValue)
jp.doubleValue.toBigDecimal()
} else {
val v = jp.embeddedObject
when (v) {
is Int -> BigDecimal(v)
is Long -> BigDecimal(v)
is Float -> BigDecimal(v.toDouble())
is Double -> BigDecimal(v)
when (val v = jp.embeddedObject) {
is Int -> v.toBigDecimal()
is Long -> v.toBigDecimal()
is Float -> v.toBigDecimal()
is Double -> v.toBigDecimal()
is Decimal128 -> v.bigDecimalValue()
is String -> BigDecimal(v)
is String -> v.toBigDecimal()
else -> throw ClassCastException(
v.javaClass.name + " cannot be cast to " + BigDecimal::class.java.name + ": " + v
)
Expand Down

0 comments on commit 83542f2

Please sign in to comment.