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

SrcGen fast-path serialization for nullable structs (#59719) #60366

Closed
wants to merge 1 commit into from

Conversation

SkiFoD
Copy link
Contributor

@SkiFoD SkiFoD commented Oct 13, 2021

No description provided.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Oct 13, 2021
@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
Copy link

ghost commented Oct 13, 2021

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

Issue Details

null

Author: SkiFoD
Assignees: -
Labels:

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

Milestone: -

@SkiFoD SkiFoD changed the title Src-Gen serialization for nullable structs (#59719) SrcGen fast-path serialization for nullable structs (#59719) Oct 13, 2021
@eiriktsarpalis
Copy link
Member

Fixes #59719.

@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Oct 15, 2021
@layomia
Copy link
Contributor

layomia commented Nov 17, 2021

Thanks for the PR and effort here @SkiFoD. Upon further investigation, it turns out that these changes are not needed because fast-path methods for underlying nullable types are already being invoked when serializing parent nullable types. The pattern for this fast-path execution remains the same:

PersonStruct? person = new()
{
    FirstName = "Jane",
    LastName = "Doe"
};

string json = JsonSerializer.Serialize(person, someContext.NullablePersonStruct); // Fast-path for person struct is invoked.

I added tests verifying this behavior here - #61711.

@layomia layomia closed this Nov 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants