-Added Serializable attribute to exceptions
-Fixed deserializing null values into DataTables -Fixed error when deserializing readonly IEnumerable<T> array properties -Fixed not including type name for byte[] values
This commit is contained in:
@@ -4310,5 +4310,24 @@ keyword such as type of business.""
|
||||
var withParameterisedConstructor = JsonConvert.DeserializeObject<DTOWithParameterisedConstructor>(json);
|
||||
Assert.AreEqual(withoutParameterisedConstructor.B, withParameterisedConstructor.B);
|
||||
}
|
||||
|
||||
public class EnumerableArrayPropertyClass
|
||||
{
|
||||
public IEnumerable<int> Numbers
|
||||
{
|
||||
get
|
||||
{
|
||||
return new[] { 1, 2, 3 }; //fails
|
||||
//return new List<int>(new[] { 1, 2, 3 }); //works
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SkipPopulatingArrayPropertyClass()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(new EnumerableArrayPropertyClass());
|
||||
JsonConvert.DeserializeObject<EnumerableArrayPropertyClass>(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -703,6 +703,56 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
}
|
||||
|
||||
public class Car
|
||||
{
|
||||
// included in JSON
|
||||
public string Model { get; set; }
|
||||
public DateTime Year { get; set; }
|
||||
public List<string> Features { get; set; }
|
||||
public object[] Objects { get; set; }
|
||||
|
||||
// ignored
|
||||
[JsonIgnore]
|
||||
public DateTime LastModified { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ByteArrays()
|
||||
{
|
||||
Car testerObject = new Car();
|
||||
byte[] data = new byte[] {75, 65, 82, 73, 82, 65};
|
||||
testerObject.Objects = new object[] { data, "prueba" };
|
||||
|
||||
JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
|
||||
jsonSettings.NullValueHandling = NullValueHandling.Ignore;
|
||||
jsonSettings.TypeNameHandling = TypeNameHandling.All;
|
||||
|
||||
string output = JsonConvert.SerializeObject(testerObject, Formatting.Indented, jsonSettings);
|
||||
|
||||
string carClassRef = ReflectionUtils.GetTypeName(typeof(Car), FormatterAssemblyStyle.Simple);
|
||||
|
||||
Assert.AreEqual(output, @"{
|
||||
""$type"": """ + carClassRef + @""",
|
||||
""Year"": ""\/Date(-62135596800000+1300)\/"",
|
||||
""Objects"": {
|
||||
""$type"": ""System.Object[], mscorlib"",
|
||||
""$values"": [
|
||||
{
|
||||
""$type"": ""System.Byte[], mscorlib"",
|
||||
""$value"": ""S0FSSVJB""
|
||||
},
|
||||
""prueba""
|
||||
]
|
||||
}
|
||||
}");
|
||||
Car obj = JsonConvert.DeserializeObject<Car>(output, jsonSettings);
|
||||
|
||||
Assert.IsNotNull(obj);
|
||||
|
||||
Assert.IsTrue(obj.Objects[0] is byte[]);
|
||||
|
||||
Assert.AreEqual(data, obj.Objects[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public class Message
|
||||
|
||||
Reference in New Issue
Block a user