Skip to content

Commit

Permalink
Merge pull request #1094 from TattsGroup/deserialize-hyphen
Browse files Browse the repository at this point in the history
Fix Json deserializion of string containing hyphens to List<string> property
  • Loading branch information
shiftkey committed Feb 11, 2016
2 parents e944742 + 3b74250 commit 3674670
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Octokit.Tests/SimpleJsonSerializerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Octokit.Helpers;
using Octokit.Internal;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
Expand Down Expand Up @@ -119,6 +120,34 @@ public void DeserializesEventInfosWithUnderscoresInName()
new SimpleJsonSerializer().Deserialize<EventInfo>(json);
}

public class MessageSingle
{
public string Message { get; private set; }
}

[Fact]
public void DeserializesStringsWithHyphensAndUnderscoresIntoString()
{
const string json = @"{""message"":""-my-test-string_with_underscores_""}";

var response = new SimpleJsonSerializer().Deserialize<MessageSingle>(json);
Assert.Equal("-my-test-string_with_underscores_", response.Message);
}

public class MessageList
{
public IReadOnlyList<string> Message { get; private set; }
}

[Fact]
public void DeserializesStringsWithHyphensAndUnderscoresIntoStringList()
{
const string json = @"{""message"":""-my-test-string_with_underscores_""}";

var response = new SimpleJsonSerializer().Deserialize<MessageList>(json);
Assert.Equal("-my-test-string_with_underscores_", response.Message[0]);
}

[Fact]
public void UnderstandsRubyCasing()
{
Expand Down
1 change: 0 additions & 1 deletion Octokit/Http/SimpleJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public override object DeserializeObject(object value, Type type)
var jsonValue = value as JsonObject;
if (stringValue != null)
{
stringValue = stringValue.Replace("-", "");
if (ReflectionUtils.GetTypeInfo(type).IsEnum)
{
// remove '-' from values coming in to be able to enum utf-8
Expand Down

0 comments on commit 3674670

Please sign in to comment.