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

Implement case sensitive property matching #2709

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

SakuraIsayeki
Copy link

@SakuraIsayeki SakuraIsayeki commented Jul 21, 2022

This PR resolves #815, by implementing a new serializer option, named PropertyCaseSensitivityHandling:

public enum PropertyCaseSensitivityHandling
{
    // Case-insensitive matching (default).
    CaseInsensitive = 0,

    // Case-sensitive matching.
    CaseSensitive = 1
}

To preserve continuity with prior implementations, default is set to CaseInsensitive.
With the new behaviour provided by CaseSensitive, we can now have differentiation and validation for casing, which is required by several API specs (Binance & xAPI, to name a few examples).

As this behaviour has an extremely lightweight implementation (only one extra check on each Property matching), it does what it says on the tin, and only that.

Most of the matching with convention-following PascalCase C# properties will fail if you don't add [JsonProperty("name")] to each property, or write some esoteric conversion between JSON standard camelCase (or whichever casing is used) and C# Properties.


A few footnotes...

This PR was inspired by the stale #601, where I factually stripped the Casing implementation to form my own.
Furthermore, as this is my first ever PR to Newtonsoft.Json (hello guys!), I might've inadvertently broken a few long-standing conventions along the way, so any feedback will be most appreciated.

@pierregarcia
Copy link

Really glad to see a PR about that. We had to fork the repo to make these changes. It would be nice to see them integrated in Newtonsoft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to do case-sensitive property deserialization
2 participants