views:

34

answers:

1

I am using http://json.codeplex.com/ and I am talking to a Ruby based Rest API. Problem is that most of the propertys 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; }
}
+1  A: 

Inherit from DefaultContractResolver and override ResolvePropertyName to format property names as you'd like.

CamelCasePropertyNamesContractResolver does a similar global change to property names.

James Newton-King
Thanks James will give it a shot and post my findings here for others who might run into this situation.
Jake Scott