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
Hugh2y 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
ffmpeg -i me -f null -
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
Hugh2y 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