Special case JSON _links property.

For some reason, the List Feeds http://developer.github.com/v3/activity/feeds/#list-feeds
API response has a field that starts with an underscore. This also occurs in
the Review Comments API: http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository
and in the Contents API. http://developer.github.com/v3/repos/contents/#get-the-readme

This commit special cases that one field so we can use the expected CLR
property name. I couldn't find a case where a
JSON response doesn't prefix "links" with an underscore.

Related to #386
This commit is contained in:
Haacked
2014-02-20 09:34:45 -08:00
parent 9257ba4f41
commit aaa010d790
2 changed files with 14 additions and 1 deletions
@@ -91,6 +91,16 @@ namespace Octokit.Tests
Assert.Equal("commit-url", result.Url);
Assert.Equal("commit-message", result.Message);
}
[Fact]
public void IgnoresUnderscore()
{
const string json = "{\"_links\":\"blah\"}";
var result = new SimpleJsonSerializer().Deserialize<Sample>(json);
Assert.Equal("blah", result.Links);
}
}
public class Sample
@@ -99,6 +109,7 @@ namespace Octokit.Tests
public string FirstName { get; set; }
public bool IsSomething { get; set; }
public bool Private { get; set; }
public string Links { get; set; }
}
}
}
+3 -1
View File
@@ -23,7 +23,9 @@ namespace Octokit.Internal
{
protected override string MapClrMemberNameToJsonFieldName(string clrPropertyName)
{
return clrPropertyName.ToRubyCase();
var rubyCased = clrPropertyName.ToRubyCase();
if (rubyCased == "links") return "_links"; // Special case for GitHub API
return rubyCased;
}
// This is overridden so that null values are omitted from serialized objects.