Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions RestSharp.Tests/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ public void Can_Deserialize_From_Root_Element()
Assert.Equal("John Sheehan", output.DisplayName);
}

[Fact]
public void Can_Deserialize_To_Dictionary_String_Object() {
var doc = File.ReadAllText(Path.Combine("SampleData", "jsondictionary.txt"));

var json = new JsonDeserializer();

var output = json.Deserialize<Dictionary<string, object>>(new RestResponse() { Content = doc });

Assert.Equal(output.Keys.Count, 3);

var firstKeysVal = output.FirstOrDefault().Value;
Assert.IsAssignableFrom<System.Collections.IDictionary>(firstKeysVal);
}

[Fact]
public void Can_Deserialize_Generic_Members()
{
Expand Down
12 changes: 11 additions & 1 deletion RestSharp/Deserializers/JsonDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,17 @@ private object ConvertValue(Type type, object value)
return CreateAndMap(type, value);
}
}
else
else if (type.IsSubclassOfRawGeneric(typeof(List<>)))
{
// handles classes that derive from List<T>
return BuildList(type, value);
}
else if (type == typeof(JsonObject))
{
// simplify JsonObject into a Dictionary<string, object>
return BuildDictionary(typeof(Dictionary<string, object>), value);
}
else
{
// nested property classes
return CreateAndMap(type, value);
Expand Down