首页 > 解决方案 > Is it possible to tell Newtonsoft to map a declared $type to a different type when deserialising?

问题描述

I have many serialized objects that have a $type property that I'd like to deserialize. However, I want to tell Newtonsoft to map to different type depending on the value of $type,

How can I do this?

E.g.

{
    "$type": "A.B.C, A.B",
    "MyProp": "MyValue"
}

I'd like Newtonsoft to interpret this as:

{
    "$type": "A.B.D, A.B",
    "MyProp": "MyValue"
}

标签: json.netjson.net

解决方案


推荐阅读