Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using XmlRoot or XmlType with RestSharp

I have been trying to Deserialize an XmlResponse using RestSharp, but have been unable to get the correct xml root to be noticed within RestSharp.

A list of MyObject are returned from the server (in xml format), and clientside I would like to serialize that xml into a List.

Everything correlates between MyObject and MyObjectDto except for the name of the class.

Applying XmlRoot and / or XmlType attributes to the class doesn't seem to help (they are disregarded in the RestSharp deserializer).

Is there any way to do this in RestSharp? Do I need to build a custom xml deserializer?

like image 222
Maixy Avatar asked May 23 '26 20:05

Maixy


1 Answers

Found the answer in a comment by John Sheehan in another post:

Serialize an object when posting data with RestSharp

XmlRoot decorations don't seem to be supported in RestSharp, but you can create a custom serializer to get the functionality that you need if your models and xml don't precisely match up.

I ended up going a different route altogether and serialized the data using the .NET xml libraries.

like image 72
Maixy Avatar answered May 26 '26 10:05

Maixy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!