diff --git a/RestSharp.Tests/JsonTests.cs b/RestSharp.Tests/JsonTests.cs index bda88777c..c656b51fc 100644 --- a/RestSharp.Tests/JsonTests.cs +++ b/RestSharp.Tests/JsonTests.cs @@ -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 output = json.Deserialize>(new RestResponse { Content = doc }); + + IDictionary dictionary = (IDictionary)output["SomeDictionary"]; + Assert.AreEqual("abra", dictionary["NonNull"]); + Assert.IsNull(dictionary["Null"]); + } + + private static string CreateJsonWithUnderscores() { JsonObject doc = new JsonObject(); diff --git a/RestSharp.Tests/RestSharp.Tests.Signed.csproj b/RestSharp.Tests/RestSharp.Tests.Signed.csproj index 8aaafc768..ae944f44e 100644 --- a/RestSharp.Tests/RestSharp.Tests.Signed.csproj +++ b/RestSharp.Tests/RestSharp.Tests.Signed.csproj @@ -142,6 +142,9 @@ Always + + Always + Always diff --git a/RestSharp.Tests/RestSharp.Tests.csproj b/RestSharp.Tests/RestSharp.Tests.csproj index 2e08d17a6..0a55a43a9 100644 --- a/RestSharp.Tests/RestSharp.Tests.csproj +++ b/RestSharp.Tests/RestSharp.Tests.csproj @@ -129,6 +129,9 @@ Always + + Always + Always diff --git a/RestSharp.Tests/SampleData/jsondictionary_null.txt b/RestSharp.Tests/SampleData/jsondictionary_null.txt new file mode 100644 index 000000000..a9b1e36c0 --- /dev/null +++ b/RestSharp.Tests/SampleData/jsondictionary_null.txt @@ -0,0 +1,7 @@ +{ + "SomeDictionary" : + { + "NonNull": "abra", + "Null": null + } +} diff --git a/RestSharp/Deserializers/JsonDeserializer.cs b/RestSharp/Deserializers/JsonDeserializer.cs index ef773c9d9..ee85e1d76 100644 --- a/RestSharp/Deserializers/JsonDeserializer.cs +++ b/RestSharp/Deserializers/JsonDeserializer.cs @@ -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(); }