Repository navigation
fix(idempotency): keep reflection-based serialization under JIT when a serialization context is set - #1375
Merged
Conversation
…a serialization context is set
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1375 +/- ##
===========================================
- Coverage 80.78% 80.78% -0.01%
===========================================
Files 306 306
Lines 13094 13098 +4
Branches 1561 1562 +1
===========================================
+ Hits 10578 10581 +3
Misses 2074 2074
- Partials 442 443 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 number: closes #1374
Summary
Changes
Under JIT, calling
WithJsonSerializationContext()made Idempotency serialize only the types in the user's context. A non-emptyTypeInfoResolverChainreplaces System.Text.Json's default reflection resolver, so anything else failed withNotSupportedExceptionwhen a record was saved or read, even a plainstring.IdempotencySerializer.AddTypeInfoResolveradds aDefaultJsonTypeInfoResolverafter the user's context when reflection-based serialization is available. Types in the context still use the context's metadata, and other types fall back to reflection, the same as without a context.[ExcludeFromCodeCoverage]helper behindJsonSerializer.IsReflectionEnabledByDefault, the same guard as the other reflection calls in this file. ILC removes it in Native AOT and trimmed apps, so they keep using only source-generated metadata.WithJsonSerializationContext()explaining that Native AOT needs every type in the context, while JIT falls back to reflection for the rest.User experience
NotSupportedException: JsonTypeInfo metadata for type 'System.String' was not provided by TypeInfoResolver of type '[MyContext]'Testing
New
SerializationContextReflectionFallbackTests:stringand a type not in the context round-trip after a context is set[Idempotent]withWithJsonSerializationContext()and a result type not in the context replays the stored resultNotSupportedExceptionsaving the record)dotnet test tests/AWS.Lambda.Powertools.Idempotency.Tests(with DynamoDB Local through Testcontainers): 109/109 on net8.0 and 109/109 on net10.0.libraries/(dotnet restore && dotnet build --configuration Release --no-restore): 0 errors.IdempotencyandIdempotency-usage.Merge danger: two-way door. Blast radius: Idempotency serialization under JIT after
WithJsonSerializationContext(). Native AOT and trimmed apps are unaffected.Checklist
Please leave checklist items unchecked if they do not apply to your change.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.