C
C#2y ago
Hugh

✅ Adding a JsonDerivedType without setting an attribute on the parent class

I'm currently using multiple JsonDerivedType attributes on a parent class so that I can get polymorphic serialization/deserialization. Is there a way that I can register derived types from elsewhere? For example, if I had another .dll with a subclass in, I won't know what the subclass is where I've defined the base class, but if the .dll has a RegisterTypes() function somewhere, is there a way that this function could add this type to the list of derived types?
3 Replies
Hugh
HughOP2y ago
This SO post: https://stackoverflow.com/questions/8513042/json-net-serialize-deserialize-derived-types, implies that if I use Newtonsoft Json, I can just set a setting and it will deal with all of this on its own
Omnissiah
Omnissiah2y ago
you can create your converters and add them to JsonSerializerSettings.Converters and use that setting globally depending if you are using mvc or not (there's .AddJsonOptions)
Hugh
HughOP2y ago
I’ve got various converters, but that wouldn’t help me here without me doing a lot of work to manually serialise members. For now I’m shifting the whole project over to using newtonsoft json
Want results from more Discord servers?
Add your server