-
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
Stop Calling JSON GetTypeInfo with the runtime type #47859
Stop Calling JSON GetTypeInfo with the runtime type #47859
Conversation
src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs
Outdated
Show resolved
Hide resolved
Calling GetTypeInfo with the object's runtime type doesn't work when using unspeakable types and using JSON source generation. There is no way to mark the unspeakable type (like a C# compiler implemented IAsyncEnumerable iterator) as JsonSerializable. Instead, when the "declared type"'s JsonTypeInfo isn't compatible with the runtime type w.r.t. polymorphism, serialize the value "as object", letting System.Text.Json's serialization take over to serialize the value. Fix dotnet#47548
c8e1046
to
c771a2a
Compare
@@ -108,9 +109,7 @@ public static partial class HttpResponseJsonExtensions | |||
/// <param name="contentType">The content-type to set on the response.</param> | |||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the operation.</param> | |||
/// <returns>The task object representing the asynchronous operation.</returns> | |||
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters |
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.
Why do these no longer apply?
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.
IDK. It builds without them... 🤷
...Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Responses.cs
Show resolved
Hide resolved
…text to shared test between RDF and RDG.
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.
LGTM! TY for migrating the test over.
Remove redundant JsonSerializerOptions.
Rename JsonTypeInfo extension method IsValid to ShouldUseWith.
OK, I have addressed all feedback. I'm going to merge this once it is green to make the 8.0-preview4 cutoff. |
This was missed in dotnet#47859 and is causing trimming/AOT warnings from generated code.
This was missed in #47859 and is causing trimming/AOT warnings from generated code.
This was missed in #47859 and is causing trimming/AOT warnings from generated code.
This was missed in #47859 and is causing trimming/AOT warnings from generated code. Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Calling GetTypeInfo with the object's runtime type doesn't work when using unspeakable types and using JSON source generation. There is no way to mark the unspeakable type (like a C# compiler implemented IAsyncEnumerable iterator) as JsonSerializable.
Instead, when the "declared type"'s JsonTypeInfo isn't compatible with the runtime type w.r.t. polymorphism, serialize the value "as object", letting System.Text.Json's serialization take over to serialize the value.
Fix #47548