diff --git a/Octokit.Tests/Http/JsonHttpPipelineTests.cs b/Octokit.Tests/Http/JsonHttpPipelineTests.cs index 9c973624..67862b79 100644 --- a/Octokit.Tests/Http/JsonHttpPipelineTests.cs +++ b/Octokit.Tests/Http/JsonHttpPipelineTests.cs @@ -132,6 +132,44 @@ namespace Octokit.Tests.Http Assert.Null(response.BodyAsObject); } + + + [Fact] + public void PerformsDataMemberAttributeMapping() + { + const string data = @"{ ""tag"":""tag-name"", + ""sha"": ""tag-sha"", + ""url"": ""tag-url"", + ""message"": ""initial version\n"", + ""tagger"": { + ""name"": ""tagger-name"", + ""email"": ""tagger-email"", + ""date"": ""2011-06-17T14:53:35-07:00"" + }, + ""object"": { + ""type"": ""commit"", + ""sha"": ""object-sha"", + ""url"": ""object-url"" + }}"; + //const string data = @"{""name"":""tag-name"",""url"":""url""}"; + + var response = new ApiResponse + { + Body = data, + ContentType = "application/json" + }; + var jsonPipeline = new JsonHttpPipeline(); + + jsonPipeline.DeserializeResponse(response); + + Assert.NotNull(response.BodyAsObject); + Assert.Equal("tag-name", response.BodyAsObject.Name); + Assert.Equal("tag-sha", response.BodyAsObject.Sha); + Assert.Equal("tag-url", response.BodyAsObject.Url); + Assert.Equal("tag-message", response.BodyAsObject.Message); + Assert.Equal("tagger.name", response.BodyAsObject.Tagger.Name); + Assert.Equal("tagger.email", response.BodyAsObject.Tagger.Email); + } } } } diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index c32c5544..75437edb 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -18,7 +18,7 @@ namespace Octokit.Internal return SimpleJson.DeserializeObject(json, _serializationStrategy); } - class GitHubSerializerStrategy : PocoJsonSerializerStrategy + class GitHubSerializerStrategy : DataContractJsonSerializerStrategy { protected override string MapClrMemberNameToJsonFieldName(string clrPropertyName) { diff --git a/Octokit/Models/Response/Tag.cs b/Octokit/Models/Response/Tag.cs index ba91b5b8..91d948aa 100644 --- a/Octokit/Models/Response/Tag.cs +++ b/Octokit/Models/Response/Tag.cs @@ -2,6 +2,7 @@ namespace Octokit { + [DataContract] public class Tag { [DataMember(Name = "tag")] diff --git a/Octokit/SimpleJson.cs b/Octokit/SimpleJson.cs index 613894b7..1352e6b0 100644 --- a/Octokit/SimpleJson.cs +++ b/Octokit/SimpleJson.cs @@ -29,7 +29,7 @@ //#define SIMPLE_JSON_DYNAMIC // NOTE: uncomment the following line to enable DataContract support. -//#define SIMPLE_JSON_DATACONTRACT +#define SIMPLE_JSON_DATACONTRACT // NOTE: uncomment the following line to disable linq expressions/compiled lambda (better performance) instead of method.invoke(). // define if you are using .net framework <= 3.0 or < WP7.5