-
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 1/3] Implement APIs needed by JSON source generator #51149
Conversation
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsContributes to #45448. This PR primarily implements the The changes are being made in chunks to avoid having one huge PR that might be way more difficult to review. The target completion date for PRs in this series is the preview 4 snap. Note to reviewers PR review can start from the third commit "Add JsonMetadataServices and APIs needed by source generator". The first two commits simply perform some refactoring:
Upcoming PRs to complete the implementation
|
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. |
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerContext.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerContext.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerContext.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerContext.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
Show resolved
Hide resolved
...em.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonMetadataServices.Collections.cs
Show resolved
Hide resolved
...tem.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonMetadataServices.Converters.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.cs
Show resolved
Hide resolved
.../System.Text.Json/src/System/Text/Json/Serialization/Attributes/JsonSerializableAttribute.cs
Outdated
Show resolved
Hide resolved
JsonIgnoreCondition ignoreCondition, | ||
JsonNumberHandling numberHandling, | ||
string propertyName, | ||
JsonEncodedText jsonPropertyName) |
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 the idea we can cache common property names together on the caller site, instead of here on the callee side which wouldn't know about the duplicated names?
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.
Yes that's the idea. The source generator/caller will keep track of duplicate property names and resolve them within the callback to return the list of JsonPropertyInfo
s. We still detect collisions when putting the infos in the dictionary for deserialization, and throw IOE
for those cases.
However, it will be possible for the same property name to be written multiple times if the caller is only serializing (and not deserializing). The source generator will not create metadata that has this behavior, but the user can construct this themselves unless we decide to validate both sides (essentially populating the deserialization cache even though we don't need to)
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs
Outdated
Show resolved
Hide resolved
...em.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonMetadataServices.Collections.cs
Outdated
Show resolved
Hide resolved
...em.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonMetadataServices.Collections.cs
Outdated
Show resolved
Hide resolved
...braries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonMetadataServices.cs
Outdated
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.
Other than minor feedback LGTM.
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 noted a few typos.
Contributes to #45448.
Note to reviewers
This PR primarily implements the
JsonMetadataServices
APIs needed by the JSON source generator when generating code in user assemblies. It is essentially a no-op to existing serializer functionality, hence, no test changes are added in this PR. Tests for the new APIs will be included in an upcoming PR that adds the source generator itself.The changes are being made in chunks to avoid having one huge PR that might be way more difficult to review. The target completion date for PRs in this series is the preview 4 snap.
PR review can start from the third commit "Add JsonMetadataServices and APIs needed by source generator". The first two commits simply perform some refactoring:
Upcoming PRs to complete the implementation
JsonSerializer
andSystem.Net.Http.Json
methods that take the new metadata classes being added in this PR ([JSON source gen 3/3] Add new methods to JsonSerializer and System.Net.Http.Json APIs that take type metadata #51528)I expect all 3 PRs to be open and reviewed concurrently, with reviewers focusing on the goal of each PR in isolation (to the degree possible). Thanks!