How to get lowercase hyphen naming convention of serialized POCO classes without DataMember attributes?



I have a very large set of POCO classes used as data contracts in WCF and model classes in Web API and I need to serialize them using lowercase hyphen convention. Using DataMember attribute one each property rings my DRY alarms.



class BankAccount{
public string AccountNumber;
}


Should be serialized as following XML:



<bank-account>
<account-number>CA123A1231</account-number>
</bank-account>


and as a following JSON:



{
"account-number":"CA123A1231"
}


I am aware of CamelCasePropertyNamesContractResolver in Json.NET so I guess I could use it as a starting point for JSON.


Any ideas on how to implement naming convention for XML using DataContractSerializer?


No comments:

Post a Comment