-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Unify JSON handling across RDF and RDG #48573
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
Conversation
...egateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt
Show resolved
Hide resolved
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointJsonPreparationEmitter.cs
Outdated
Show resolved
Hide resolved
@@ -276,7 +277,7 @@ async ValueTask<Todo> ValueTaskTestActionAwaited() | |||
} | |||
} | |||
|
|||
[Theory] | |||
[ConditionalTheory(Skip = "https://github.com/dotnet/runtime/issues/87073")] |
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.
Your change is regressing this scenario because we are now ALWAYS calling GetTypeInfo(typeof(object))
? Is that correct? (this test is passing in main) Maybe we shouldn't be doing this change if it is going to regress scenarios. I just thought you were hitting issues in new tests you were converting (for filters).
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.
Your change is regressing this scenario because we are now ALWAYS calling GetTypeInfo(typeof(object))? Is that correct?
Yes, although it's only regressing the scenario when a JsonContext is used.
Maybe we shouldn't be doing this change if it is going to regress scenarios.
I think we should still do it, but I'm comfortable waiting until the bug fix in the runtime is merged to merge this in to our repo.
I just thought you were hitting issues in new tests you were converting (for filters).
The filters scenario was to showcase that the bug was happening in RDF as well and wasn't a side-effect of RDG's codegen, but as we eventually realized, any invocation of GetTypeInfo(typeof(object))
will trigger this at the moment.
...DelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt
Outdated
Show resolved
Hide resolved
...DelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt
Outdated
Show resolved
Hide resolved
...DelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt
Outdated
Show resolved
Hide resolved
...DelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt
Outdated
Show resolved
Hide resolved
...DelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt
Show resolved
Hide resolved
b0644fb
to
1a5e6bb
Compare
1a5e6bb
to
fba3643
Compare
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. Just a couple small nits/questions
...xtensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt
Outdated
Show resolved
Hide resolved
var runtimeType = value?.GetType(); | ||
if (runtimeType is null || jsonTypeInfo.Type == runtimeType || jsonTypeInfo.PolymorphismOptions is not null) | ||
{ | ||
return httpContext.Response.WriteAsJsonAsync(value!, jsonTypeInfo); |
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.
return httpContext.Response.WriteAsJsonAsync(value!, jsonTypeInfo); | |
return httpContext.Response.WriteAsJsonAsync(value, jsonTypeInfo); |
This seems wrong because when value
is null, we get here.
Maybe the right fix is to take a JsonTypeInfo<T?> jsonTypeInfo
?
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.
Yep, I tweaked the nullability in a9b8d8b
RDG currently resolves the
JsonTypeInfo
when deserializing a request body parameter once per request. This applies an update to the codegen so that theJsonTypeInfo
is resolved once at delegate construction and then re-used for each request.RDG's implementation for response writing is currently slightly different from what RDF uses. There's a work item to make a public API (#47973) here but for now we unify the two implementations.