How to serialize class type but not the namespace to a Json string using DataContractJsonSerializer

后端 未结 6 1567
太阳男子
太阳男子 2021-02-05 21:17

I\'m trying to serialize a class hierarchy to a Json string using DataContractJsonSerializer, in a WCF service. the default behaviour for serializing a derived clas

6条回答
  •  温柔的废话
    2021-02-05 21:31

    Note: I typed up this answer below and later realized that DataContractResolver is currently not supported with DataContractJsonSerializer. It may soon be with the next release of the framework, however. This is also useful if you are looking at more than just JSON.

    **

    You can do this with a DataContractResolver, which lets you map types to xsi:type (__type) information and vice-versa in a custom manner.

    To do this, check out this blog post on DataContractResolver, plus this conceptual topic, plus this sample

提交回复
热议问题