I am trying to use RestSharp to consume a third-party REST web service and I am having some trouble getting the default XML deserialization to work with the XML I am getting back.
The XML is in the form -
<root>
<someURL href="192.168.1.1" />
<anotherURL href="192.168.1.2" />
<thirdURL href="192.168.1.3" />
</root>
My request.RootElement is set to "root" and I originally tried creating the following object for RestSharp to deserialize into -
public class URLInfo
{
public string someURL { get; set; }
public string anotherURL { get; set; }
public string thirdURL { get; set; }
}
I realised this wouldn't work because of the attributes so I thought based on the example here (https://github.com/restsharp/RestSharp/wiki/Deserialization) - even though this talks about a list of elements, I tried creating the following -
public class URLInfo
{
public HrefAttribute someURL { get; set; }
public HrefAttribute anotherURL { get; set; }
public HrefAttribute thirdURL { get; set; }
}
public class HrefAttribute
{
public string href { get; set; }
}
But my response object data is still null. Could anyone point out what i'm doing wrong here, or is it not even possible to use the default XmlDeserializer when attributes are involved? - This would seem strange as their own example talks about attributes, albeit in a list.
Thanks.
Ok, it appears it was setting the root that breaking it!
When I removed the call to
request.RootElement = "root";
It went on to deserialize the document no problem. Hmm... Would be interested to still know why this fixed it as it seems to be the correct root?