-Fix deserializing nullable array
This commit is contained in:
@@ -3353,5 +3353,24 @@ keyword such as type of business.""
|
||||
|
||||
Assert.AreEqual(2, newDictionary.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeNullableArray()
|
||||
{
|
||||
string jsonText = JsonConvert.SerializeObject(new double?[] { 2.4, 4.3, null }, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
2.4,
|
||||
4.3,
|
||||
null
|
||||
]", jsonText);
|
||||
|
||||
double?[] d = (double?[])JsonConvert.DeserializeObject(jsonText, typeof(double?[]));
|
||||
|
||||
Assert.AreEqual(3, d.Length);
|
||||
Assert.AreEqual(2.4, d[0]);
|
||||
Assert.AreEqual(4.3, d[1]);
|
||||
Assert.AreEqual(null, d[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,8 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
internal IWrappedCollection CreateWrapper(object list)
|
||||
{
|
||||
if (list is IList && (CollectionItemType == null || !_isCollectionItemTypeNullableType))
|
||||
if ((list is IList && (CollectionItemType == null || !_isCollectionItemTypeNullableType))
|
||||
|| UnderlyingType.IsArray)
|
||||
return new CollectionWrapper<object>((IList)list);
|
||||
|
||||
if (_genericWrapperType == null)
|
||||
|
||||
Reference in New Issue
Block a user