Skip to content

Commit

Permalink
merged in pr #737
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hallett committed Aug 26, 2015
2 parents fe1fa9e + 98863df commit 0ef81fd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
12 changes: 12 additions & 0 deletions RestSharp.Tests/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,18 @@ public void Can_Deserialize_Plain_Values()
Assert.AreEqual(result, new Guid("c02bdd1e-cce3-4b9c-8473-165e6e93b92a"));
}

[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 @@ -204,8 +204,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

0 comments on commit 0ef81fd

Please sign in to comment.