-Fix deserializing nullable array

This commit is contained in:
JamesNK
2010-03-27 07:17:11 +00:00
parent b0c6db675e
commit 0f148a9788
2 changed files with 21 additions and 1 deletions
@@ -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)