Skip to content

Commit

Permalink
Double uppercase issue (#1601)
Browse files Browse the repository at this point in the history
* Addressed double-cap deserializing issue w/ tests

* Updated to use predefined cultureInfo property
  • Loading branch information
shipsaw committed Jul 15, 2021
1 parent 0d42f78 commit c544837
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/RestSharp/Serializers/Json/JsonSerializer.cs
Expand Up @@ -120,7 +120,7 @@ object Map(object target, IDictionary<string, object> data)
if (!data.TryGetValue(name, out var value))
{
var parts = name.Split('.');
var currentData = data;
IDictionary<string, object> currentData = new Dictionary<string, object>(data, StringComparer.Create(Culture, true));

for (var i = 0; i < parts.Length; ++i)
{
Expand Down
11 changes: 11 additions & 0 deletions test/RestSharp.Tests/JsonTests.cs
Expand Up @@ -436,6 +436,17 @@ public void Can_Deserialize_Lists_of_Simple_Types()
Assert.IsNotEmpty(output.Numbers);
}

[Test]
public void Can_Deserialize_Names_With_Double_Uppercase()
{
var doc = JsonData.CreateJsonWithDoubleUppercase();
var serializer = new JsonSerializer();
var response = new RestResponse { Content = doc };
var p = serializer.Deserialize<PersonForJson>(response);

Assert.AreEqual(435, p.PersonId);
}

[Test]
public void Can_Deserialize_Names_With_Dashes_With_Default_Root()
{
Expand Down
2 changes: 2 additions & 0 deletions test/RestSharp.Tests/SampleClasses/misc.cs
Expand Up @@ -127,6 +127,8 @@ public class PersonForJson
public Order Order { get; set; }

public Disposition Disposition { get; set; }

public int PersonId { get; set; }
}

public enum Order { First, Second, Third }
Expand Down
9 changes: 9 additions & 0 deletions test/RestSharp.Tests/TestData/JsonData.cs
Expand Up @@ -126,6 +126,15 @@ public static string CreateJsonWithDashes()
return doc.ToString();
}

public static string CreateJsonWithDoubleUppercase()
{
var doc = new JsonObject
{
["personID"] = 435,
};
return doc.ToString();
}

public static string CreateJson()
{
var doc = new JsonObject
Expand Down

0 comments on commit c544837

Please sign in to comment.