public void ComplexSingleItemArrayPropertySerialization() { TestComplexArrayClass o = new TestComplexArrayClass { Name = "Hi", Products = new List <Product> { new Product { Name = "First" } } }; string output = JsonConvert.SerializeObject(o, new IsoDateTimeConverter()); XmlDocument xmlProduct = JsonConvert.DeserializeXmlNode(output, "test", true); Assert.AreEqual(@"<test> <Name>Hi</Name> <Products json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json""> <Name>First</Name> <ExpiryDate>2000-01-01T00:00:00Z</ExpiryDate> <Price>0</Price> <Sizes /> </Products> </test>", IndentXml(xmlProduct.InnerXml)); string output2 = JsonConvert.SerializeXmlNode(xmlProduct.DocumentElement, Formatting.Indented, true); Assert.AreEqual(@"{ ""Name"": ""Hi"", ""Products"": [ { ""Name"": ""First"", ""ExpiryDate"": ""2000-01-01T00:00:00Z"", ""Price"": ""0"", ""Sizes"": null } ] }", output2); }
public void ComplexSingleItemArrayPropertySerialization() { TestComplexArrayClass o = new TestComplexArrayClass { Name = "Hi", Products = new List<Product> { new Product { Name = "First" } } }; string output = JsonConvert.SerializeObject(o, new IsoDateTimeConverter()); XmlDocument xmlProduct = JsonConvert.DeserializeXmlNode(output, "test", true); Assert.AreEqual(@"<test> <Name>Hi</Name> <Products json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json""> <Name>First</Name> <ExpiryDate>2000-01-01T00:00:00Z</ExpiryDate> <Price>0</Price> <Sizes /> </Products> </test>", IndentXml(xmlProduct.InnerXml)); string output2 = JsonConvert.SerializeXmlNode(xmlProduct.DocumentElement, Formatting.Indented, true); Assert.AreEqual(@"{ ""Name"": ""Hi"", ""Products"": [ { ""Name"": ""First"", ""ExpiryDate"": ""2000-01-01T00:00:00Z"", ""Price"": ""0"", ""Sizes"": null } ] }", output2); }