Skip to content

Preserve floating-point JSON literals as BSON doubles - #2033

Open
IamPritamAcharya wants to merge 2 commits into
mongodb:mainfrom
IamPritamAcharya:JAVA-2031
Open

Preserve floating-point JSON literals as BSON doubles#2033
IamPritamAcharya wants to merge 2 commits into
mongodb:mainfrom
IamPritamAcharya:JAVA-2031

Conversation

@IamPritamAcharya

Copy link
Copy Markdown

Description

Fixes an issue where floating-point JSON literals with an integral
numeric value were encoded as integer BSON types.

For example, 3.0 was previously encoded as INT32 because trailing
zeros were stripped before determining the BSON numeric type.

This change preserves the original floating-point notation when
encoding JSON numbers:

  • 3INT32
  • 3.0DOUBLE
  • 15.9DOUBLE
  • 1.0E20DOUBLE
  • -0.0DOUBLE

The existing BigDecimal behavior is preserved for values that should
remain DECIMAL128.

Tests

  • Added regression coverage for decimal and exponent notation.
  • Added signed-zero coverage.
  • Added out-of-range floating-point coverage.
  • ./gradlew spotlessApply :bson-kotlinx:check passes.

Related to #2031

@IamPritamAcharya
IamPritamAcharya requested a review from a team as a code owner August 10, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant