Add DocumentJsonConverter for System.Text.Json serialization support#4347
Merged
dscpinheiro merged 6 commits intodevelopmentfrom Mar 17, 2026
Merged
Add DocumentJsonConverter for System.Text.Json serialization support#4347dscpinheiro merged 6 commits intodevelopmentfrom
dscpinheiro merged 6 commits intodevelopmentfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes System.Text.Json serialization/deserialization for Amazon.Runtime.Documents.Document by adding a dedicated STJ converter so Document is no longer treated as an IEnumerable collection during serialization, and aligns Document.FromObject numeric parsing behavior with existing runtime unmarshalling logic.
Changes:
- Added an internal
DocumentJsonConverterand applied it toDocumentvia[JsonConverter]. - Updated
Document.FromObjectto preferTryGetInt32beforeTryGetInt64. - Added unit tests covering primitive/collection serialization, round-trips, and regressions; added a patch DevConfig entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sdk/src/Core/Amazon.Runtime/Documents/DocumentJsonConverter.cs | Implements STJ converter to serialize/deserialize Document by its DocumentType rather than via IEnumerable. |
| sdk/src/Core/Amazon.Runtime/Documents/Document.cs | Applies the converter attribute and updates FromObject number parsing to try int before long. |
| sdk/test/UnitTests/Custom/Runtime/Documents/DocumentJsonConverterTests.cs | Adds coverage for the new converter, including regressions and customer scenarios. |
| generator/.DevConfigs/180bd698-bd6a-4799-a23e-db90f89660d6.json | Declares a patch-level core changelog entry for the fix. |
normj
previously approved these changes
Mar 13, 2026
Member
normj
left a comment
There was a problem hiding this comment.
Very cool PR. This will help make working with JSON and Documents.
dscpinheiro
reviewed
Mar 13, 2026
dscpinheiro
approved these changes
Mar 17, 2026
muhammad-othman
approved these changes
Mar 17, 2026
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.
Description
Add
DocumentJsonConverterto fixSystem.Text.Jsonserialization ofDocumenttypes.DocumentimplementsIEnumerableinterfaces which causes STJ to treat it as a collection, throwingInvalidDocumentTypeConversionExceptionfor non-list/non-dictionary types.Also fixes
Document.FromObjectnumber parsing to tryTryGetInt32beforeTryGetInt64, consistent withDocumentUnmarshaller.Motivation and Context
Fixes #3694, #3837, #4078.
Testing
dotnet test --filter "FullyQualifiedName~Document"→ 26 passed, 0 failed.Breaking Changes Assessment
No breaking changes.
DocumentJsonConverterisinternal sealed. The[JsonConverter]attribute changes STJ behavior from broken (throws) to correct. Customer workarounds (custom converters inJsonSerializerOptions) take precedence per STJ resolution order.Types of changes
Checklist
License