-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
JsonSubtypes does not respect naming strategy for discriminator property value #80
Comments
Hi @egovova11 Thanks for submitting this issue ! Please note that the code provided is only compatible with var serializerSettings = new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy(),
},
Converters = new List<JsonConverter>
{
new StringEnumConverter
{
NamingStrategy = new SnakeCaseNamingStrategy()
},
JsonSubtypesConverterBuilder
.Of(typeof(IMyType), "enum_value") // <--- here you have to provide the json property name
.RegisterSubtype(typeof(MyTypeOne), EnumType.EnumMemberOne)
.RegisterSubtype(typeof(MyTypeTwo), EnumType.EnumMemberTwo)
.Build()
}
} I can reproduce the bug described, it's due to the fact that reading the discriminator property doesn't seem to use the converter provided for the property. The problem is located here: But I have no idea how use |
Yeah, I used exactly the same approach to workaround the issue. Thanks for pointing to the code location, I'll give it a thought. Maybe I will be able to come up with some solution for that. |
I've finally found a fix, see PR #93 |
Description
The issue occurs when naming strategy other than CamelCase is used.
Source/destination types
Source/destination JSON
Expected behavior
JSON is deserialized correctly with regard to naming strategy settings.
Actual behavior
Deserialization fails with the following message:
System.ArgumentException: Could not convert 'enum_member_one' to EnumType. ---> Newtonsoft.Json.JsonSerializationException: Error converting value "enum_member_one" to type 'Namespace.EnumType'. Path 'enum_value', line 1, position 13. ---> System.ArgumentException: Requested value 'enum_member_one' was not found.
Steps to reproduce
The text was updated successfully, but these errors were encountered: