-Merge
This commit is contained in:
@@ -977,6 +977,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()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1645,9 +1645,10 @@ namespace Newtonsoft.Json.Converters
|
|||||||
if (typeof(XmlNode).IsAssignableFrom(objectType))
|
if (typeof(XmlNode).IsAssignableFrom(objectType))
|
||||||
{
|
{
|
||||||
if (objectType != typeof(XmlDocument)
|
if (objectType != typeof(XmlDocument)
|
||||||
|
&& objectType != typeof(XmlElement)
|
||||||
&& objectType != typeof(XmlNode))
|
&& objectType != typeof(XmlNode))
|
||||||
{
|
{
|
||||||
throw JsonSerializationException.Create(reader, "XmlNodeConverter only supports deserializing XmlDocuments");
|
throw JsonSerializationException.Create(reader, "XmlNodeConverter only supports deserializing XmlDocument or XmlElement.");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument d = new XmlDocument();
|
XmlDocument d = new XmlDocument();
|
||||||
@@ -1685,6 +1686,12 @@ namespace Newtonsoft.Json.Converters
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_XML_DOCUMENT
|
||||||
|
if (objectType == typeof(XmlElement))
|
||||||
|
{
|
||||||
|
return document.DocumentElement.WrappedNode;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return document.WrappedNode;
|
return document.WrappedNode;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user