diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs index d19ae72e..4ec29cfb 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs @@ -1556,6 +1556,19 @@ namespace Newtonsoft.Json.Tests.Serialization ]", json); } #endif + + [Test] + public void EmptyStringInHashtableIsDeserialized() + { + string externalJson = @"{""$type"":""System.Collections.Hashtable, mscorlib"",""testkey"":""""}"; + + JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; + + JsonConvert.SerializeObject(new Hashtable { { "testkey", "" } }, settings); + Hashtable deserializeTest2 = JsonConvert.DeserializeObject(externalJson, settings); + + Assert.AreEqual(deserializeTest2["testkey"], ""); + } } #if !(NET40 || NET35 || NET20 || PORTABLE40) diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index 592c95a5..97d452b5 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -279,7 +279,7 @@ namespace Newtonsoft.Json.Serialization string s = (string)reader.Value; // convert empty string to null automatically for nullable types - if (string.IsNullOrEmpty(s) && objectType != typeof(string) && objectType != typeof(object) && contract != null && contract.IsNullable) + if (string.IsNullOrEmpty(s) && objectType != null && objectType != typeof(string) && objectType != typeof(object) && contract != null && contract.IsNullable) return null; // string that needs to be returned as a byte array should be base 64 decoded