Skip to content

Commit dc6b920

Browse files
Fix writing as an integer when the number is a decimal
Signed-off-by: Mark <mark.vogel@nomadgcs.com>
1 parent ea548ef commit dc6b920

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bson-kotlinx/src/main/kotlin/org/bson/codecs/kotlinx/BsonEncoder.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ internal class DefaultBsonEncoder(
218218
else -> {
219219
val decimal = BigDecimal(content)
220220
when {
221-
decimal.stripTrailingZeros().scale() > 0 &&
222-
DOUBLE_MIN_VALUE <= decimal && decimal <= DOUBLE_MAX_VALUE ->
223-
encodeDouble(element.double)
221+
decimal.stripTrailingZeros().scale() > 0 ->
222+
if (DOUBLE_MIN_VALUE <= decimal && decimal <= DOUBLE_MAX_VALUE) {
223+
encodeDouble(element.double)
224+
} else {
225+
writer.writeDecimal128(Decimal128(decimal))
226+
}
224227
INT_MIN_VALUE <= decimal && decimal <= INT_MAX_VALUE ->
225228
encodeInt(element.int)
226229
LONG_MIN_VALUE <= decimal && decimal <= LONG_MAX_VALUE ->

0 commit comments

Comments
 (0)