I'm having trouble deserializing an XML response from an API call. My 'Option' object's property 'Description' is null.
Below is a sample of the XML:
<vehicle found="1">
<description>VehicleDescText</description>
<buildDate>2000-11-20</buildDate>
<modelYear>2001</modelYear>
<optionList>
<option code="UH8">OptionDesc1</option>
<option code="UH8">OptionDesc2</option>
</optionList>
</vehicle>
Here is a sample of C# classes:
[DataContract]
[XmlRoot("vehicle")]
public class Vehicle
{
[DataMember]
[XmlAttribute("found")]
public bool Found { get; set; }
[DataMember]
[XmlElement("description")]
public string Description { get; set; }
[DataMember]
[XmlElement("buildDate")]
public string BuildDate { get; set; }
[DataMember]
[XmlElement("modelYear")]
public string ModelYear { get; set; }
[DataMember]
[XmlElement("optionList")]
public List<Option> OptionList { get; set; }
}
public class Option
{
[DataMember]
[XmlAttribute("code")]
public string Code { get; set; }
[DataMember]
[XmlElement("option")]
public string Description { get; set; }
}
Deserializing the object looks like this:
var xmlDeserializer = new RestSharp.Deserializers.XmlDeserializer();
results = xmlDeserializer.Deserialize<Vehicle>(response);
Where am I going wrong here? As I would prefer not to modify the underlying data model, what Attributes can I add or modify to fix the problem?