Shaun Arundell
Shaun Arundell

Reputation: 11

RestSharp - List<T> XmlDeserialize property name mapping

Restshap only Deserializes my XML and maps to my List<BankStatementItemDetail> when I give it a property name of 'Results' (I found this name by looking into the response..base..content).

There is no sign of the name 'Results' in the corresponding element in the XML. If I use the element name in the XML - BankStatementItemDetail (i.e List<BankStatementItemDetail> BankStatementItemDetails) it fails.

On other occasions I have had to append 'List' to the property name to get it to map. I don't understand List property name mapping. Are they documented, the documents I have seen make no mention of a property called 'Results'.

Can anybody elucidate the rules for me ?

my structure

public class BankStatementItemList
{
    public double openingBalance;
    public List<=BankStatementItemDetail=> Results { get; set; }
    public class BankStatementItemDetail
    {
        public string Id { get; set; }
        public Fund Fund { get; set; }
        public BankAccount BankAccount { get; set; }
        public DateTime TransactionDate { set; get; }
        public String DebitCreditIndicator { set; get; }
        public String LodgementReference { set; get; }
        // not in the xml
        public Double Debit { set; get; }
        public Double Credit { set; get; }
        public Double Balance { set; get; }
    }
    public class BankAccount
    {
        public string Code { get; set; }
        public string ScopeCode { get; set; }
        public string Description { get; set; }
    }
    public class Fund
    {
        public string Code { get; set; }
        public string ScopeCode { get; set; }
        public string Description { get; set; }
    }
}

Some of the XML

<BankStatementItemList xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BankStatementItemDetail Key="95eb97a7-9be4-4d95-be47-ef2113414bf5">...</BankStatementItemDetail>
<BankStatementItemDetail Key="fd414e7f-5f12-4414-94eb-11ab4a6b5f7b">...</BankStatementItemDetail>
<BankStatementItemDetail Key="c7ed29dd-ef4a-4def-a486-60f5c6ac4253">

Upvotes: 0

Views: 431

Answers (1)

iboros
iboros

Reputation: 337

This is how you'd do the mapping.

[XmlElement(ElementName = "Results")]
[SerializeAs(Name = "Results")]
public string BankStatementItemDetail{ get; set; }

Upvotes: 1

Related Questions