JSON deserialization to inherited types
Asked Answered
E

1

14

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.

Echinate answered 25/11, 2010 at 1:16 Comment(0)
H
10

json.net has the ability to preserve references

And it supports storing the type

Hydrocortisone answered 29/11, 2010 at 14:37 Comment(2)
Well preserving references isn't what I'm looking for and is a different functionality. But type inheritance is...Echinate
As I understand the documentation the TypeNameHandling setting makes json.net store the typename. And you talked about "complex object graphs" so I think you need that feature too.Hydrocortisone

© 2022 - 2024 — McMap. All rights reserved.