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

Fix case-insensitive JSON deserialization of default enum vals #112028

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

Conversation

PranavSenthilnathan
Copy link
Member

Fixes #110745

The JSON serializer supports deserializing an enum from the default name (the C# enum member name) even when a naming policy is used. For example, both "enum_value" and "EnumValue" will be deserialized to MyEnum.EnumValue when lower snake casing is specified:

enum MyEnum { EnumValue }

However, there is a regression in .NET 9.0 when the enum default name is the same as the name from the naming policy:

// Both work in .NET 8.0 but throw in .NET 9.0
Console.WriteLine(JsonSerializer.Deserialize<MyEnum>("\"Example\"", options));
Console.WriteLine(JsonSerializer.Deserialize<MyEnum>("\"Another_Example\"", options));

enum MyEnum
{ 
  example,
  another_example
}

This PR changes this back to the .NET 8.0 behavior.

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

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

Successfully merging this pull request may close these issues.

System.Text.Json 9.0 can break case-insensitive enum deserialization when there is a naming policy
1 participant