-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Describe the bug
When using JsonKnownTypes on existing json content, adding a new derived type and then decorating the base class with the basic [JsonConverter...] attribute results in an exception:
To Reproduce
Steps to reproduce the behavior:
- Create a base class
- Serialize this class using standard Newtonsoft behaviors, no type handling
- Implement a new derived class
- Decorate the base class with the JsonConverter for JsonKnownTypes
- Deserialize
Expected behavior
I would expect an instance without a discriminator to automatically deserialize to the base class
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Exception content:
JsonKnownTypes.Exceptions.JsonKnownTypesException: discriminator is not registered for T type
I then tried adding [JsonKnownTypeFallback(typeof(Base))]
This results in another exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'Base' to type 'Derived'.
Two unexpected behaviors here!
I would be very happy to help implement a solution here!