-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding STJ Polymorphism to Result Types #46008
Adding STJ Polymorphism to Result Types #46008
Conversation
Removing the change from HttpResultsHelper to HttpResultsWriter to avoid polluting the git with not related changes and I will do it later.
This needs a rebase. My PR enables trimming/AOT analysis on this project. You may have new warnings. |
[RequiresDynamicCode(JsonHttpResultTrimmerWarning.SerializationRequiresDynamicCodeMessage)] | ||
[RequiresUnreferencedCode(JsonHttpResultTrimmerWarning.SerializationUnreferencedCodeMessage)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me why this is unsafe after the other work we did to make the underlying JSON APIs that these call into safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unsafe because it is the scenario where the user provides the options, could be resolved by DI or not, so, we need to check and initialize for reflection.
@davidfowl after our conversation i tried to capture the feedback about the |
I'll take your silence as "OK" 😁😁😁😁 and mark it as auto-merge. We can follow-up with this in another PR if you want, ok? |
Fixes #44852
This PR enables support
System.Text.Json
polymorphism configuration (eg.:JsonDerivedAttribute
) by calling theS.T.J.GetTypeInfo
APIs to check if the declared type is polymorphic safe (value types
,sealed types
or hasjson polymorphism options
), if not, will fall back to use theJsonTypeInfo
obtained from the runtime type.Also, this PR introduces new
[Typed]Results
APIs that allow users to provideJsonTypeInfo
andJsonSerializerContext
when using aJsonHttpResult
(API Approved: #46252)Contributes #45527
This PR resolves the following warnings:
Benchmark results
Summary
JsonTypeInfo
+Serialize methods
slower than callSerializer
directly runtime#807503
(2GetTypeInfo
calls) does not show huge performance regressions: ~ 0.3%1 - Fast path
Results
Sample
Results
2 - Runtime type check (1 `GetTypeInfo` calls)
Sample
Results
3 - Polymorphic with Runtime type check (2 `GetTypeInfo` calls)
Sample
Results