-Fixed empty string being changed to null on object properties
This commit is contained in:
@@ -5286,6 +5286,18 @@ keyword such as type of business.""
|
|||||||
|
|
||||||
Assert.AreEqual(new WidgetId1 { Value = 1234 }, w.Id);
|
Assert.AreEqual(new WidgetId1 { Value = 1234 }, w.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SerializeDictionaryStringStringAndStringObject()
|
||||||
|
{
|
||||||
|
var serializer = JsonSerializer.Create(new JsonSerializerSettings());
|
||||||
|
var dict = serializer.Deserialize<Dictionary<string, string>>(new JsonTextReader(new StringReader("{'k1':'','k2':'v2'}")));
|
||||||
|
|
||||||
|
var reader = new JsonTextReader(new StringReader("{'k1':'','k2':'v2'}"));
|
||||||
|
var dict2 = serializer.Deserialize<Dictionary<string, object>>(reader);
|
||||||
|
|
||||||
|
Assert.AreEqual(dict["k1"], dict2["k1"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Widget1
|
public class Widget1
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
return EnsureType(reader, reader.Value, CultureInfo.InvariantCulture, contract, objectType);
|
return EnsureType(reader, reader.Value, CultureInfo.InvariantCulture, contract, objectType);
|
||||||
case JsonToken.String:
|
case JsonToken.String:
|
||||||
// convert empty string to null automatically for nullable types
|
// 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;
|
return null;
|
||||||
|
|
||||||
// string that needs to be returned as a byte array should be base 64 decoded
|
// string that needs to be returned as a byte array should be base 64 decoded
|
||||||
|
|||||||
Reference in New Issue
Block a user