RestSharp serialization to JSON, object is not using SerializeAs attribute as expected

前端 未结 5 1782
北荒
北荒 2020-11-30 11:36

I am using RestSharp (version 104.4 via NuGet) to make calls to a Rest Web Service. I have designed a set of objects (POCO) which matches resources exposed

5条回答
  •  醉酒成梦
    2020-11-30 11:44

    RestSharp uses SimpleJson. This library doesn't know or respect the [SerializeAs] attribute (which is XML-only anyway), it just outputs the POCO's property name, unless it's compiled with #SIMPLE_JSON_DATACONTRACT defined, then you can use the [DataContract] attribute to rename properties.

    So your options seem to be to recompile the SimpleJson library with that define and decorate your properties with the [DataContract(Name="lowercasepropertyname")] attribute, or create a custom serializer that uses a JSON serializer that does respect other attributes as suggested in @Ryan's answer.

提交回复
热议问题