Skip to content

STJ: Adding support for JsonNamingPolicyAttribute #117079

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dannyd89
Copy link
Contributor

Implements #108232

My first walk in this park, so some guidance is very much appreciated.

Not sure if I shouldn't add a JsonNamingPolicy property to JsonTypeInfo, might make some stuff cleaner.

Still missing

  • JsonMetadataServices.Helpers.cs
  • Tests
  • Anything else I probably missed

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 27, 2025
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.

@dannyd89
Copy link
Contributor Author

cc: @eiriktsarpalis maybe you could take a quick look if the direction is right

@eiriktsarpalis
Copy link
Member

Not sure if I shouldn't add a JsonNamingPolicy property to JsonTypeInfo, might make some stuff cleaner.

I don't think that would be necessary, the final computed name should simply be reflected in the Name property. As a general note, any added public API must match what was approved in review.

@@ -52,14 +52,14 @@
<Project Path="tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj" />
</Folder>
<Folder Name="/tools/" />
<Folder Name="/tools/gen/">
<Folder Name="/tools/gen/" Id="5ad0b2ae-1660-5889-7060-a20f14d475b9">
Copy link
Member

Choose a reason for hiding this comment

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

What's this?

JsonKnownNamingPolicy.SnakeCaseLower => JsonNamingPolicy.SnakeCaseLower,
JsonKnownNamingPolicy.SnakeCaseUpper => JsonNamingPolicy.SnakeCaseUpper,
JsonKnownNamingPolicy.KebabCaseLower => JsonNamingPolicy.KebabCaseLower,
_ => JsonNamingPolicy.CamelCase,
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't feel right to me, an invalid policy should probably result in no changes being made. It should probably also trigger a diagnostic if using the source generator.

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.

Your approach looks good to me, carry on :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Text.Json community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants