I am using RestSharp to communicate with a remote server. I receive a JSON serialized string, which i am able to deserialize into a c# object. I also am able to deserialize json arrays to List. However, i want those objects to be used in WPF bindings so i would need to put them in an ObservableCollection for convenience. However, if i try to change the property from List to ObservableCollection (or IList, or ICollection, or Collection) i get an exception on deserialization.
Unable to cast object of type 'RestSharp.JsonArray' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]
The underlying code is really not special, but here it is anyway:
private ObservableCollection<StationDto> stations;
[JsonProperty(PropertyName = "stations")]
public ObservableCollection<StationDto> Stations
{
get { return this.stations; }
set
{
this.stations = value;
RaisePropertyChanged(() => Stations);
}
}
I understand that Interfaces won't work cause Json.net needs a concrete class to serialize to.
I have done a fair amount of googling but i have not seen a solution for this. Is there a pattern that is commonly used for hand-crafted proxies used for json/rest services?