-
-
Notifications
You must be signed in to change notification settings - Fork 192
EnumStringConverter fails on Enum serialization when multiple members have same value #856
Description
Nuget Package
Json.More.Net
Package Version
2.1.0
Operating System
Windows
.Net Target (if relevant, please specify the version in the description)
.Net (5 or after)
A clear and concise description of the bug.
EnumStringConverter fails on Enum serialization when multiple members have same value.
This could be reproduced by Serializing System.Net.HttpStatusCode which has both members (Ambiguous, MultipleChoices) assigned to same value (300).
What did you expect?
While this is really edge case scenario, I would say that since C# supports such enum declaration, EnumStringConverter should conform to it.
When serializing, I would expect that it should rely on member name or member DescriptionAttribute without value.
When deserializing, I assume library doesnt support parsing number values, therefore no changes required.
Please add test code or steps to reproduce the behavior.
JsonSerializer.Serialize(HttpStatusCode.BadRequest, new JsonSerializerOptions { Converters = { new EnumStringConverter<HttpStatusCode>() } });
Is there any other information you'd like to share regarding this bug?
Converter fails in EnsureMap() method since it tries to create write cache dictionary based on enum values, which does not support duplicates.
Code of Conduct & Contributor Guidelines
- I agree to follow this project's Code of Conduct and Contribution Guidelines.