-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[JSON source gen 3/3] Add new methods to JsonSerializer and System.Net.Http.Json APIs that take type metadata #51528
Conversation
Tagging subscribers to this area: @eiriktsarpalis, @layomia |
Note regarding the 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. |
b4feeff
to
908ba2c
Compare
…take type metadata
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http.Json/tests/FunctionalTests/JsonContext/String.cs
Show resolved
Hide resolved
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; some nits and a couple questions.
src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs
Show resolved
Hide resolved
...ibraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Helpers.cs
Show resolved
Hide resolved
...xt.Json/tests/System.Text.Json.Tests/Serialization/MetadataTests/JsonContext/HighLowTemps.cs
Outdated
Show resolved
Hide resolved
...ext.Json/tests/System.Text.Json.Tests/Serialization/MetadataTests/JsonContext/JsonContext.cs
Show resolved
Hide resolved
} | ||
private static JsonPropertyInfo[] PersonPropInitFunc(JsonSerializerContext context) | ||
{ | ||
JsonContext jsonContext = (JsonContext)context; |
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.
Can this cast ever fail?
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.
It should never, unless we have a bug (e.g. a weird cross-pollination of options instances being used). The serializer should only pass the same context instance that the type info instance was a property on.
I'll think about this some more. We could be more defensive in the gen'd code and throw InvalidOperationException
instead of leak InvalidCastException
.
To avoid any potential issues here entirely, we could make the method non-static and reference the context directly (instead of taking it as an argument), but I want to be sure of any perf implications first.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs
Show resolved
Hide resolved
Hello @layomia! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
/backport to release/6.0-preview4 |
Started backporting to release/6.0-preview4: https://github.com/dotnet/runtime/actions/runs/768780136 |
@layomia backporting to release/6.0-preview4 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Add new methods to JsonSerializer and System.Net.Http.Json APIs that take type metadata
.git/rebase-apply/patch:2505: trailing whitespace.
.git/rebase-apply/patch:2538: trailing whitespace.
.git/rebase-apply/patch:2551: trailing whitespace.
.git/rebase-apply/patch:2826: trailing whitespace.
.git/rebase-apply/patch:2859: trailing whitespace.
warning: squelched 6 whitespace errors
warning: 11 lines add whitespace errors.
Using index info to reconstruct a base tree...
M src/libraries/System.Text.Json/ref/System.Text.Json.cs
M src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Utf8JsonWriter.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
M src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
A src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/DeserializationWrapper.cs
A src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataServicesTests/MetadataServicesTests.Options.cs
A src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataServicesTests/MetadataServicesTests.cs
A src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/SerializationWrapper.cs
A src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Text.Json/tests/System.Text.Json.Tests.csproj
CONFLICT (rename/rename): Rename "src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataServicesTests/MetadataServicesTests.cs"->"src/libraries/System.Text.Json/tests/Serialization/MetadataServicesTests/MetadataServicesTests.cs" in branch "HEAD" rename "src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataServicesTests/MetadataServicesTests.cs"->"src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataTests/MetadataTests.JsonMetadataServices.cs" in "Add new methods to JsonSerializer and System.Net.Http.Json APIs that take type metadata"
Auto-merging src/libraries/System.Text.Json/tests/Serialization/MetadataServicesTests/MetadataServicesTests.cs and src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataTests/MetadataTests.JsonMetadataServices.cs, both renamed from src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataServicesTests/MetadataServicesTests.cs
CONFLICT (rename/rename): Rename "src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataServicesTests/MetadataServicesTests.Options.cs"->"src/libraries/System.Text.Json/tests/Serialization/MetadataServicesTests/MetadataServicesTests.Options.cs" in branch "HEAD" rename "src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataServicesTests/MetadataServicesTests.Options.cs"->"src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/MetadataTests/MetadataTests.Options.cs" in "Add new methods to JsonSerializer and System.Net.Http.Json APIs that take type metadata"
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStack.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Utf8JsonWriter.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Utf8JsonWriter.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
Auto-merging src/libraries/System.Text.Json/ref/System.Text.Json.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/ref/System.Text.Json.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Add new methods to JsonSerializer and System.Net.Http.Json APIs that take type metadata
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
I think the backport is failing because the 2/3 PR hasn't been merged yet |
/backport to release/6.0-preview4 |
Started backporting to release/6.0-preview4: https://github.com/dotnet/runtime/actions/runs/768827649 |
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.
Everything in 2/3 and 3/3 LGTM, aside from one nit.
...es/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs
Show resolved
Hide resolved
...es/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs
Show resolved
Hide resolved
@tdykstra @carlossanlop I think it's great that docs folks are able to review the docs in the exact same PR that we have implementation and tests. That has to be so much more efficient long term. |
Contributes to #45448.
PR 1 - #51149
PR 2 - #51300
PR 3 - this PR
This PR completes the initial implementation of the source generator needed for community feedback (preview 4) and for Blazor to adopt the new pattern. cc @CoffeeFlux, @eerhardt, @ericstj, @Anipik.
#51544 tracks the remaining S.N.H.J APIs we need to add.
cc @jozkee for System.Net.Http.Json changes.