-Added DeserializeAnonymousType overload with JsonSerializerSettings
-Added support for specifying the root type when serialize JSON to use with TypeNameHandling.Auto -Fixed recursively reading type wrapper objects when deserializing
This commit is contained in:
@@ -580,6 +580,30 @@ keyword such as type of business.""
|
||||
Assert.AreEqual("TestProduct", anonymous.Product.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnonymousObjectSerializationWithSetting()
|
||||
{
|
||||
DateTime d = new DateTime(2000, 1, 1);
|
||||
|
||||
var anonymous =
|
||||
new
|
||||
{
|
||||
DateValue = d
|
||||
};
|
||||
|
||||
JsonSerializerSettings settings = new JsonSerializerSettings();
|
||||
settings.Converters.Add(new IsoDateTimeConverter
|
||||
{
|
||||
DateTimeFormat = "yyyy"
|
||||
});
|
||||
|
||||
string json = JsonConvert.SerializeObject(anonymous, settings);
|
||||
Assert.AreEqual(@"{""DateValue"":""2000""}", json);
|
||||
|
||||
anonymous = JsonConvert.DeserializeAnonymousType(json, anonymous, settings);
|
||||
Assert.AreEqual(d, anonymous.DateValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CustomCollectionSerialization()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user