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

Add ReferenceHandler to JsonSourceGenerationOptions #109174

Merged

Conversation

PranavSenthilnathan
Copy link
Member

Adds a ReferenceHandler property to JsonSourceGenerationOptions to allow users to specify how references are handled when generating source code for JSON types.

Implements #107597

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, 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.

1 similar comment
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, 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.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 24, 2024
Copy link
Contributor

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

@@ -1433,6 +1437,9 @@ private static string FormatIgnoreCondition(JsonIgnoreCondition ignoreCondition)
private static string FormatJsonSerializerDefaults(JsonSerializerDefaults defaults)
=> SourceGeneratorHelpers.FormatEnumLiteral(JsonSerializerDefaultsTypeRef, defaults);

private static string FormatReferenceHandler(JsonKnownReferenceHandler referenceHandler)
=> SourceGeneratorHelpers.FormatEnumLiteral(ReferenceHandlerTypeRef, referenceHandler);
Copy link
Member

Choose a reason for hiding this comment

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

Not saying that this wouldn't work, but ReferenceHandler isn't technically an enum. It's a class with static properties, so perhaps different concerns apply to formatting it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The default value of the enum didn't map to a default reference handler in the first iteration of this PR. Updated the PR to handle this enum -> reference handler object conversion. Note that for the naming policy, we actually have the policy classes in the Common folder so nameof works there. I tried to see if I could also move ReferenceHandler to Common but it has a couple of dependencies so I just left it as it is instead of adding a bunch of types to Common. I just hardcoded the property names for this PR.

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Left some feedback, but this looks great so far 👍

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Thanks!

@eiriktsarpalis eiriktsarpalis merged commit 3648d83 into dotnet:main Oct 26, 2024
83 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2024
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.

2 participants