-
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
Consider consolidating logic of JSON Snake/Kebab naming with Camel #77262
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsIn #69613 we've added Snake/Kebab casing but it uses slightly different word splitting logic. We should decide which we prefer and consider consolidating the code.
|
If it gets approved, please assign it on me. I already know how to fix it policies which are merged initially were made taking an approach allowing customization of word transform and the separator. |
camelCase conversion doesn't require splitting tokens -- it simply converts the first group of uppercase characters to lowercase on a fixed-length string: runtime/src/libraries/System.Text.Json/Common/JsonCamelCaseNamingPolicy.cs Lines 32 to 57 in 24813dc
Consolidating the logic would introduce complexity where it shouldn't exist. Why would we want to do this? |
type ``Lemme break your code :trollface:``() =
member _.M() = () |
As of .NET 7, the CamelCase policy has the following behavior: > JsonNamingPolicy.CamelCase.ConvertName <| nameof ``Lemme break your code :trollface:`` ;;
val it: string = "lemme break your code :trollface:" and changing that would be a breaking change. |
Without jokes, in my previous attempt of making naming policies I analyzed implementation in other libraries and platforms. Anywhere else policies are implemented exactly as @krwq wrote, i.e., split an input into words, transform them using some logic and concatenate them. When I asked you about As I noticed you in the PR, most likely it won't pass "it's written in stone" rule, but let's think that it won't affect too many users and with each release there are breaking changes already (: |
We don't do this out of spite :-) Unlike libraries shipped in NuGet which can be governed by things like SemVer, STJ is (also) part of the .NET shared framework; as such any regression/breaking change could have the potential to prevent entire teams from migrating to the next version of .NET. Accidental breaking changes will always be serviced, and the bar for introducing intentional breaking changes is very high (and pretty involved from a paperwork perspective). I may or may not agree with the current implementation of
This needs to be backed by evidence. For users that are affected the problem will manifest silently, as in the serializer would end up writing data using a different JSON schema. |
@YohDeadfall I'd suggest compiling a list of differences in behavior (i.e. table with examples). If we were to make this change we'd possibly introduce compat switch. We'll likely need more upvotes on this issue to proceed though |
Hard to point to any exact place in the original PR since there was a discussion about rules, so you have to check at least a half of dotnet/corefx#41354. Some links are provided by a @ahsonkhan in dotnet/corefx#41354 (comment). For my package and merged changes, I also checked Rust libraries, especially heck. To conclude, usually name transformers use the same method under the hood to parse an input string and then work on extracted words using rule specific to each policy like lower casing and an underscore as separator. I say usually because I have faced no library which does policies differently, but it might exist since I checked popular only. |
In #69613 we've added Snake/Kebab casing but it uses slightly different word splitting logic. We should decide which we prefer and consider consolidating the code.
cc: @YohDeadfall
The text was updated successfully, but these errors were encountered: