Allow [Parameter] to control JSON Field Names.

Previously, SimpleJsonSerializer.MapClrMemberNameToJsonFieldName
special cased the name "Links" since while that was the name of the
property in the object model, in JSON "_links" was used instead.

It turns out that there was an additional problem, where GitReference
wants to expose as Repository, but the name in JSON responses is
"repo".  Instead of simply adding another special case to
MapClrMemberNameToJsonFieldName, we update the implementation of the
serializer to allow [Parameter(Key = "some_name")] to denote what name
we'd like to use for the field in the JSON object when we serialize.
This commit is contained in:
Matt G. Ellis
2014-11-17 22:52:01 -08:00
parent 808ffe6081
commit d0dcbe8fb6
3 changed files with 17 additions and 8 deletions
+2 -1
View File
@@ -135,7 +135,7 @@ namespace Octokit.Tests
}
[Fact]
public void IgnoresUnderscore()
public void RespectsParameterKeyName()
{
const string json = "{\"_links\":\"blah\"}";
@@ -151,6 +151,7 @@ namespace Octokit.Tests
public string FirstName { get; set; }
public bool IsSomething { get; set; }
public bool Private { get; set; }
[Parameter(Key = "_links")]
public string Links { get; set; }
}
}