neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.36k stars 267 forks source link

Case Insensitive Deserialize String to Enum #178

Open tandasima opened 4 years ago

tandasima commented 4 years ago

Does Utf8json support converting strings to Enums case insensitive? So far it looks like it doesn't but I'm not entirely sure.

public enum Pet
{
    Cat,
    ....
}

I would like to be able to deserialize "cat", "CAT", "caT"... to Pet.Cat enum.

I know in Enums Cat and cat are different, however, its not in my use-case and would like whatever case that comes in the payload to match the only Cat in the enum.

Basically, I would like to accomplish something similar to this: https://stackoverflow.com/questions/2441290/javascriptserializer-json-serialization-of-enum-as-string

I'd really appreciate any guidance if this is possible.

gorillapower commented 4 years ago

@tandasima did you find a solution to this? I am also looking for a case insensitive resolver.

vborovikov commented 4 years ago

Looks like default EnumFormatter implementation doesn't support that.

tandasima commented 3 years ago

@gorillapower I ended up writing my own resolver.