File tree Expand file tree Collapse file tree
bson-kotlinx/src/main/kotlin/org/bson/codecs/kotlinx Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -100,12 +100,14 @@ internal class JsonBsonEncoder(
100100 else -> {
101101 val decimal = BigDecimal (content).stripTrailingZeros()
102102 when {
103- decimal.scale() > 0 ->
104- if (decimal.abs() <= DOUBLE_MAX_VALUE ) {
105- encodeDouble(primitive.double)
103+ decimal.scale() > 0 -> {
104+ val abs = decimal.abs()
105+ if ((decimal.signum() == 0 || abs >= DOUBLE_MIN_VALUE ) && abs <= DOUBLE_MAX_VALUE ) {
106+ encodeDouble(decimal.toDouble())
106107 } else {
107108 writer.writeDecimal128(Decimal128 (decimal))
108109 }
110+ }
109111 INT_MIN_VALUE <= decimal && decimal <= INT_MAX_VALUE -> encodeInt(decimal.toInt())
110112 LONG_MIN_VALUE <= decimal && decimal <= LONG_MAX_VALUE -> encodeLong(decimal.toLong())
111113 else -> writer.writeDecimal128(Decimal128 (decimal))
You can’t perform that action at this time.
0 commit comments