fix(core): deserialize numeric members to number when the reviver is active - #8247
Open
RasengunShotaro wants to merge 1 commit into
Open
fix(core): deserialize numeric members to number when the reviver is active#8247RasengunShotaro wants to merge 1 commit into
RasengunShotaro wants to merge 1 commit into
Conversation
4 tasks
RasengunShotaro
force-pushed
the
fix/numeric-members-revived-value
branch
from
August 4, 2026 07:22
35bd507 to
276e7e7
Compare
…active `needsReviver` returns true when a response schema contains a bigInteger, bigDecimal or document member, which enables the JSON.parse reviver for the whole body. `jsonReviver` then rewrites every numeric literal that does not round-trip, including literals belonging to plain numeric members, and the shape deserializer passed those through unchanged. As a result a member whose generated type is `number` could deserialize to a `NumericValue`. This is silent: `typeof score` becomes `"object"` and `score + 1` evaluates to the string `"1.01"` instead of `2`. Numeric members now coerce a revived `NumericValue` or `BigInt` back to `number`, matching the generated types and the behaviour prior to 3.977.0. Documents keep the revived representation, which is unchanged. One existing expectation is updated: `scalar` is a numeric member, so `1.123456789012345678E16` now deserializes to `11234567890123456`, which is what `JSON.parse` produced before the reviver was introduced. That test guards against throwing in the reviver, and it still does.
RasengunShotaro
force-pushed
the
fix/numeric-members-revived-value
branch
from
August 4, 2026 07:23
276e7e7 to
a08ef68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
#8246
Description
needsReviverreturnstruewhen a response schema contains a bigInteger, bigDecimal or document member, which enables theJSON.parsereviver for the whole body.jsonReviverthen rewrites every numeric literal that does not round-trip (1.0,0.0,1e3, anything pastNumber.MAX_SAFE_INTEGER), including literals that belong to plain numeric members, and the shape deserializer passed those values through unchanged.The result is that a member whose generated type is
numbercan deserialize to aNumericValue. It fails silently:typeof result.scorebecomes"object"andresult.score + 1evaluates to the string"1.01"instead of2. TypeScript cannot catch it, because the generated type saysscore?: number, so atypeof x === "number"guard looks redundant and is a candidate for removal.This affects any client whose response shape contains a document member. It was found on
bedrock-agent-runtimeRetrieve, whereRetrievalResultMetadataisMap<String, Document>: the knowledge base returns page numbers as22.0insidemetadata, and the relevancescorein the same response was corrupted as collateral for exact1.0/0.0values.Numeric members now coerce a revived
NumericValueorBigIntback tonumber, which matches the generated types and the behaviour before@aws-sdk/core@3.977.0. Documents keep the revived representation, which is unchanged and appears intended.Applied to both codecs (
JsonShapeDeserializerandJsonShapeDeserializer2) so v1/v2 equivalence is preserved.Testing
Added a test to each codec spec asserting that a numeric member deserializes to
numberwhile the reviver is active (1.0→1,0.0→0,1e3→1000). Both fail without the change:Full protocols suite after the change: 32 files, 516 passed, 2 skipped.
One existing expectation is updated. In
JsonShapeDeserializer2.spec.ts,fractional exponent with many digits does not throw in reviverasserted that{"scalar": 1.123456789012345678E16}stays aNumericValue.scalaris a numeric member, andJSON.parseproduced11234567890123456for that input before the reviver existed, so the expectation is changed to that value. The purpose of the test — that the reviver does not throw — is unaffected, and the neighbouringv1/v2equivalence cases still pass.I could not run the repo's full
yarninstall locally, so verification was scoped topackages-internal/core/src/submodules/protocolswith dependencies installed from npm.Checklist
*.integ.spec.ts) or E2E tests.@public,@internaltags and enabled doc generation on the package. Remember that access level annotations go below the description, not above.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.