Adds test for deserializing XmlElement and a minor change in the exception message
This commit is contained in:
@@ -906,6 +906,23 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
return sw.ToString();
|
return sw.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Foo2
|
||||||
|
{
|
||||||
|
public XmlElement Bar { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SerializeAndDeserializeXmlElement()
|
||||||
|
{
|
||||||
|
Foo2 foo = new Foo2 { Bar = null };
|
||||||
|
string json = JsonConvert.SerializeObject(foo);
|
||||||
|
|
||||||
|
Assert.AreEqual(@"{""Bar"":null}", json);
|
||||||
|
Foo2 foo2 = JsonConvert.DeserializeObject<Foo2>(json);
|
||||||
|
|
||||||
|
Assert.IsNull(foo2.Bar);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SingleTextNode()
|
public void SingleTextNode()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1433,7 +1433,7 @@ namespace Newtonsoft.Json.Converters
|
|||||||
{
|
{
|
||||||
if (objectType != typeof(XmlDocument) && objectType != typeof(XmlElement))
|
if (objectType != typeof(XmlDocument) && objectType != typeof(XmlElement))
|
||||||
{
|
{
|
||||||
throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments or XmlElement");
|
throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocument or XmlElement");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument d = new XmlDocument();
|
XmlDocument d = new XmlDocument();
|
||||||
|
|||||||
Reference in New Issue
Block a user