-Added generic JsonConvert.SerializeObject methods

-Fixed JToken.ToObject not using StringEnumConverter on enums
This commit is contained in:
James Newton-King
2015-12-09 08:45:36 +13:00
parent 45936d58a2
commit 2c7a51c50a
8 changed files with 222 additions and 9 deletions
@@ -245,6 +245,34 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
}
[Test]
public void SerializeRootTypeNameAutoWithJsonConvert_Generic()
{
string json = JsonConvert.SerializeObject<object>(new WagePerson(), Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
});
StringAssert.AreEqual(@"{
""$type"": ""Newtonsoft.Json.Tests.TestObjects.WagePerson, Newtonsoft.Json.Tests"",
""HourlyWage"": 0.0,
""Name"": null,
""BirthDate"": ""0001-01-01T00:00:00"",
""LastModified"": ""0001-01-01T00:00:00""
}", json);
}
[Test]
public void SerializeRootTypeNameAutoWithJsonConvert_Generic2()
{
string json = JsonConvert.SerializeObject<object>(new WagePerson(), new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
});
StringAssert.AreEqual(@"{""$type"":""Newtonsoft.Json.Tests.TestObjects.WagePerson, Newtonsoft.Json.Tests"",""HourlyWage"":0.0,""Name"":null,""BirthDate"":""0001-01-01T00:00:00"",""LastModified"":""0001-01-01T00:00:00""}", json);
}
public class Wrapper
{
public IList<EmployeeReference> Array { get; set; }