JSON deserialization to inherited types
-
28-09-2019 - |
Question
I have a data table in my database where I store various settings. Since they are of any type (even complex object graphs) I decided to store their values as serialized JSON strings.
Let's say that I serialized a List<ItemBase>
. Serialized string looks just fine. But the problem is that list items are of various types that are inherited from ItemBase
(which may as well be abstract for what I care).
Question
Which (de)serialization class/library should I use so my JSON strings will be correctly deserialized to correct object instances.
Solution
json.net has the ability to preserve references
And it supports storing the type
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow