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
13 changes: 13 additions & 0 deletions RestSharp.Tests/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,19 @@ public void Can_Deserialize_Dictionary_of_Lists()
Assert.IsNotEmpty(output.EmployeesPay);
}

[Test]
public void Can_Deserialize_Dictionary_with_Null()
{
string doc = File.ReadAllText(Path.Combine("SampleData", "jsondictionary_null.txt"));
JsonDeserializer json = new JsonDeserializer { RootElement = "response" };
IDictionary<string, object> output = json.Deserialize<Dictionary<string, object>>(new RestResponse { Content = doc });

IDictionary<string, object> dictionary = (IDictionary<string, object>)output["SomeDictionary"];
Assert.AreEqual("abra", dictionary["NonNull"]);
Assert.IsNull(dictionary["Null"]);
}


private static string CreateJsonWithUnderscores()
{
JsonObject doc = new JsonObject();
Expand Down
3 changes: 3 additions & 0 deletions RestSharp.Tests/RestSharp.Tests.Signed.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
<Content Include="SampleData\jsondictionary.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="SampleData\jsondictionary_null.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="SampleData\jsonenumtypes.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
3 changes: 3 additions & 0 deletions RestSharp.Tests/RestSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<Content Include="SampleData\iso8601datetimes.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="SampleData\jsondictionary_null.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="SampleData\jsondictionary_KeysType.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
7 changes: 7 additions & 0 deletions RestSharp.Tests/SampleData/jsondictionary_null.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"SomeDictionary" :
{
"NonNull": "abra",
"Null": null
}
}
6 changes: 5 additions & 1 deletion RestSharp/Deserializers/JsonDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,12 @@ private object ConvertValue(Type type, object value)
type = type.GetGenericArguments()[0];
}

if (type == typeof(object) && value != null)
if (type == typeof(object))
{
if (value == null)
{
return null;
}
type = value.GetType();
}

Expand Down