I am using http://json.codeplex.com/ and I am talking to a Ruby based Rest API. Problem is that most of the properties have a ruby underscore naming convention. I am wondering if anyone knows of a way so that I can avoid having to Add lots of JsonProperty.
For example I want to avoid adding the JsonProperty attribute and have a convention built into the serializer settings so that it knows to try and map properties with an underscore in the to the .NET naming convention :)
public class Member { [JsonProperty(PropertyName = "avatar_url")] public string AvatarUrl { get; set; } [JsonProperty(PropertyName = "twitter_screen_name")] public string TwitterScreenName { get; set; } [JsonProperty(PropertyName = "website_url")] public string WebSiteUrl { get; set; } }
Update - September 2016:
Json.NET 9.0.1 has SnakeCaseNamingStrategy. You can use that to have twitter_screen_name style properties automatically.
Inherit from DefaultContractResolver
and override ResolvePropertyName
to format property names as you'd like.
CamelCasePropertyNamesContractResolver
does a similar global change to property names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With