Skip to content
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 support required properties #73063

Merged
merged 4 commits into from
Aug 2, 2022
Merged

Conversation

krwq
Copy link
Member

@krwq krwq commented Jul 29, 2022

Fixes: #29861

In #72937 I've added internal support for required properties and required keyword. This is a continuation of that which makes it public.

Since APIs haven't been reviewed yet and source gen part is not finished yet marking this as draft.

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

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.

@ghost ghost assigned krwq Jul 29, 2022
@ghost
Copy link

ghost commented Jul 29, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #29861

In #72937 I've added internal support for required properties and required keyword. This is a continuation of that which makes it public.

Since APIs haven't been reviewed yet and source gen part is not finished yet marking this as draft.

Author: krwq
Assignees: -
Labels:

area-System.Text.Json, new-api-needs-documentation

Milestone: -

@krwq
Copy link
Member Author

krwq commented Aug 1, 2022

Some note for the last two commits: there is no test logic change in there, tests are only adapted so that they can be run both to use source gen and regular reflection resolver. The last commit actually makes it work on source gen (all source gen variants of tests are failing without that change and all pass with that change)

if (memberMetadata.IsRequired)
{
sb.Append($@"
{propertyInfoVarName}.IsRequired = true;");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we wish to set other applicable properties directly on JsonPropertyInfo rather than the intermediate JsonPropertyInfoValues (e.g. IsExtensionData)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking we could probably get rid of most of the usages of JsonMetadataServices but that might be a bit more work since we'd have to refactor also JsonTypeInfo part. While I could start doing it gradually it probably makes more sense to do it in one go but for that we need to be able to customize parameters which currently contract customization doesn't support. The reason this one is separate is because it doesn't have API in JsonMetadataServices but because we can avoid adding such API I went ahead and did it this way. I'll keep changes in this PR to minimum, we can revisit this once we get full parameters support

public JsonRequiredAttribute()
{
}
public JsonRequiredAttribute() { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't the default constructor be removed here? Or is it required by ApiCompat?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not, I followed existing pattern with JsonInclude. We can put better xml doc comment I guess

@eiriktsarpalis eiriktsarpalis added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 2, 2022
@eiriktsarpalis
Copy link
Member

eiriktsarpalis commented Aug 2, 2022

Marking NO-MERGE pending API approval of #29861

@krwq krwq marked this pull request as ready for review August 2, 2022 16:22
@eiriktsarpalis eiriktsarpalis removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 2, 2022
@krwq krwq merged commit 18d0367 into dotnet:main Aug 2, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a concept of "Required" properties
4 participants