DataContractJsonSerializer and Enums

后端 未结 5 1682
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 22:42

When I serialize a enum value using DataContractJsonSerializer, it serializes the numerical value of the enum, not the string name.

IE:

enum foo
{
          


        
5条回答
  •  Happy的楠姐
    2020-12-05 23:04

    I have put together all of the pieces of this solution using the Newtonsoft.Json library in a way that works within WCF. It fixes the enum issue and also makes the error handling much better, and it works in IIS hosted services. It's quite a lot of code, so you can find it on GitHub here: https://github.com/jongrant/wcfjsonserializer/blob/master/NewtonsoftJsonFormatter.cs

    You have to add some entries to your Web.config to get it to work, you can see an example file here: https://github.com/jongrant/wcfjsonserializer/blob/master/Web.config

提交回复
热议问题