2

I am currently having an issue when using Simple.OData.Client to retrieve an object.

Here's the call, using an instance of ODataClient

RecurringObjectView model = await client.For<RecurringObjectView>("RecurringObjects")
                                        .Key(id)
                                        .Expand(r => r.RecurrenceSetting)
                                        .FindEntryAsync();

I'm able to trace the data coming from the API, and all is well. Below is an extract of the Json being return by the server.

{
    "RecurrenceSetting": {
        "@odata.type":"#Namespace.Of.The.DailyRecurrenceSettingView",
        "Id":16
        // more settings...
     }
     // more values...
}

The issue is that the RecurrenceSetting object is abstract, and in turn is giving the following error...

Unable to create an instance of type RecurrenceSettingView that does not have a default constructor.

For reference purposes, here are extracts of the class definitions...

public class RecurringObjectView
{
    public int Id { get; set; }

    public virtual RecurrenceSettingView RecurrenceSetting { get; set; }

    // loads more properties...
}


public abstract class RecurrenceSettingView
{
    public int Id { get; set; }

    // common recurrence setting properties...
}

public class DailyRecurrenceSettingView :
    RecurrenceSettingView
{
    // daily specific settings...
}
  • 1
    So which type should the client instantiate when deserializing a `RecurrenceSettingView` and how should it know that? – CodeCaster May 31 '16 at 13:47
  • @CodeCaster I've edited the question and added some of the Json that is being returned by the server. The "@odata.type":"#Namespace.Of.The.DailyRecurrenceSettingView", should be sufficient to deserialize the correct concret object. – Richard Ueckermann May 31 '16 at 14:07
  • You're right. That is, if the client library supports it. It should use `@odata.type` to feed hints to the serializer. – CodeCaster May 31 '16 at 14:09
  • @CodeCaster Agreed! Either I'm missing something or it doesn't in fact support it... which is kinda a pain! – Richard Ueckermann May 31 '16 at 14:18

0 Answers0