JSON序列将继承类型序列、类型、JSON

2023-09-03 10:56:10 作者:巷陌i

我在我的数据库中的数据表,我储存的各种设置。由于他们是任何类型的(即使是复杂的对象图)的,我决定来存储它们的值序列化的JSON字符串。

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.

让我们说,我序列化一个名单,其中,ItemBase> 。序列化字符串看起来就好了。但问题是,列表项是指从 ItemBase 继承的各类(可能还有是抽象的,我也不在乎)的。

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).

这(德)序列化类/库我应该用,所以我的JSON字符串将被正确地反序列化到正确的对象实例。

Which (de)serialization class/library should I use so my JSON strings will be correctly deserialized to correct object instances.

推荐答案

json.net 有能力 preserve引用

和它支持的storing类型