georgeci
georgeci

Reputation: 347

How to deserialize attribute named “value” with RestSharp without breaking the code style?

I am using RestSharp to deserialize a XML file where some of the nodes are like this:

<clouds value="68" name="broken clouds"/>

The elementes with an attribute called 'value' will not deserialize.

My class:

public class CloudsData
{        
    public string value { get; set; }

    public string Name { get; set; } 

}

Renaming "Value" to "value" helps, but breaking the Code Style. Are there other ways to solve this problem?

Upvotes: 2

Views: 2363

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125630

Mark your property with SerializeAsAttribute:

public class CloudsData
{        
    [SerializeAs(Name = "value")]
    public string value { get; set; }

    [SerializeAs(Name = "name")]
    public string Name { get; set; } 
}

Upvotes: 4

Related Questions