You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#71933 by adding a new JsonTypeInfo.OriginatingResolver public property that is used by source generated JsonSerializerContext instances to register themselves with JsonTypeInfo instances that they generate. This information can be used to determine if the fast-path serialization delegate is compatible with the current configuration, even if the originating JsonSerializerContext is encapsulated behind a custom resolver.
Note regarding the new-api-needs-documentation label:
This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.
Issue Details
Fixes #71933 by adding a new JsonTypeInfo.OriginatingResolver public property that is used by source generated JsonSerializerContext instances to register themselves with JsonTypeInfo instances that they generate. This information can be used to determine if the fast-path serialization delegate is compatible with the current configuration, even if the originating JsonSerializerContext is encapsulated behind a custom resolver.
NB the new property hasn't been approved in API review yet.
Do we actually need new API? I can see at least two ways we can do it without new API:
not assign SerializeHandler in cases where fast path should not be used - we can move the fast path checking logic to a generated context.
another option is we wrap every context with combined (as effective resolver, from user perspective they wouldn't know about it). Then combined one could check if all contexts are compatible between each other and with the options. Then combined context can decide if fast path can be used (so rather than checking if resolver is context we check if it's combined resolver and go from there)
the second option might be easier and should be compatible with contexts generated in previous versions
not assign SerializeHandler in cases where fast path should not be used - we can move the fast path checking logic to a generated context.
That might just work actually. We could remove the runtime invalidation altogether and just decide if the fast path should be assigned at the context layer.
not assign SerializeHandler in cases where fast path should not be used - we can move the fast path checking logic to a generated context.
That might just work actually. We could remove the runtime invalidation altogether and just decide if the fast path should be assigned at the context layer.
Actually, I was wrong about this. We would still need to expose new API but even then this cannot account for contexts generated by older versions of the sdk; we still need to do this invalidation in the JsonTypeInfo layer.
The reason will be displayed to describe this comment to others. Learn more.
It could be false if you're configuring recursive types. Checking IsConfigured on JsonPropertyInfo is a different story, it completes regardless of cycles.
ghost
locked as resolved and limited conversation to collaborators
Mar 11, 2023
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
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.
Fixes#71933 by adding a new
JsonTypeInfo.OriginatingResolverpublic property that is used by source generatedJsonSerializerContextinstances to register themselves withJsonTypeInfoinstances that they generate. This information can be used to determine if the fast-path serialization delegate is compatible with the current configuration, even if the originatingJsonSerializerContextis encapsulated behind a custom resolver.