diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 61fa66dc..d407433c 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -5286,6 +5286,18 @@ keyword such as type of business."" Assert.AreEqual(new WidgetId1 { Value = 1234 }, w.Id); } + + [Test] + public void SerializeDictionaryStringStringAndStringObject() + { + var serializer = JsonSerializer.Create(new JsonSerializerSettings()); + var dict = serializer.Deserialize>(new JsonTextReader(new StringReader("{'k1':'','k2':'v2'}"))); + + var reader = new JsonTextReader(new StringReader("{'k1':'','k2':'v2'}")); + var dict2 = serializer.Deserialize>(reader); + + Assert.AreEqual(dict["k1"], dict2["k1"]); + } } public class Widget1 diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index 50e8d5a6..3d332738 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -244,7 +244,7 @@ namespace Newtonsoft.Json.Serialization return EnsureType(reader, reader.Value, CultureInfo.InvariantCulture, contract, objectType); case JsonToken.String: // convert empty string to null automatically for nullable types - if (string.IsNullOrEmpty((string) reader.Value) && objectType != typeof(string) && contract.IsNullable) + if (string.IsNullOrEmpty((string)reader.Value) && objectType != typeof(string) && objectType != typeof(object) && contract.IsNullable) return null; // string that needs to be returned as a byte array should be base 64 decoded