Skip to content

CORE-64: Fix JSONWire to write finite float/double values as JSON numbers regardless of magnitude#1261

Open
KealanTolandChronicle wants to merge 1 commit into
developfrom
bugfix/CORE-64-fix-jsonwire-large-float-double-serialisation
Open

CORE-64: Fix JSONWire to write finite float/double values as JSON numbers regardless of magnitude#1261
KealanTolandChronicle wants to merge 1 commit into
developfrom
bugfix/CORE-64-fix-jsonwire-large-float-double-serialisation

Conversation

@KealanTolandChronicle

Copy link
Copy Markdown
Contributor

Summary

  • JSONWire.writeSpecialFloatValueToBytes and writeSpecialDoubleValueToBytes now only quote values that are IEEE754 non-finite (NaN, ±Infinity). Finite values with large magnitudes are written as unquoted JSON numbers.

Motivation

Float values with magnitude ≥ 1e6 were being serialised as quoted string literals (e.g. "5000000.0") rather than JSON numbers (5000000.0). JSON consumers expecting a numeric type rejected the output. The same path affects double values ≥ 1e15.

Changes

  • JSONWire.JSONValueOut.writeSpecialFloatValueToBytes - quotes only NaN/Infinity; writes finite values unquoted
  • JSONWire.JSONValueOut.writeSpecialDoubleValueToBytes - same as above
  • JsonWireDoubleAndFloatSpecialValuesAcceptanceTests - adds largeFiniteFloatSerialiseAsJsonNumber and largeFiniteDoubleSerialiseAsJsonNumber parameterised tests; existing NaN/±Infinity round-trip tests continue to pass

Test plan

  • JsonWireDoubleAndFloatSpecialValuesAcceptanceTests - all tests pass
  • JSONNanTest - NaN still serialises as "NaN"
  • FloatDtoTest - existing DTO round-trip unaffected

…bers regardless of magnitude

IEEE754 non-finite values (NaN, ±Infinity) are quoted as JSON string literals because JSON has no numeric representation for them. Finite values, including those with large magnitudes routed through writeSpecialFloatValueToBytes / writeSpecialDoubleValueToBytes, are written as unquoted JSON numbers.

Adds parameterised acceptance tests covering large finite float and double values alongside the existing NaN / Infinity round-trip tests.
@KealanTolandChronicle KealanTolandChronicle requested review from peter-lawrey and tgd and removed request for tgd May 29, 2026 14:19

@tgd tgd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benbonavia @james-mcsherry please also review

@tgd tgd requested review from benbonavia and james-mcsherry May 29, 2026 15:38
@sonarqubecloud

Copy link
Copy Markdown

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.

4 participants