Overcoat custom server response for each resource path mapping to a class

233 views Asked by At

I am attempting to consume a REST service in an iOS app. I am using Overcoat.

In my OVCHTTPRequestOperationManager subclass I have the following:

+ (NSDictionary *)modelClassesByResourcePath {
    return @{
            @"users/*" : [SCUser class],
            @"user/*" : [SCUser class],
            @"card/*" : [SCCreditCard class],
            @"cards*" : [SCCreditCard class]
    };
}

+ (NSDictionary *)responseClassesByResourcePath{
    return @{
             @"cards" : [SCCardResponse class]
    };
}

I want to serialize a JSON payload like this:

{
    "total": 2,
    "cards": [
        {
            "balance": 1000.0,
            "ownerName": "Test One",
        },
        {
            "balance": 100.0,
            "ownerName": "Test Two",
        },
        ...
}

So far all is good, but when I try to get the cards from the response object, I get an array of NSDictionaryobjects, and not an array of SCCreditCard objects.

Has anyone had this? How to solve it?

1

There are 1 answers

0
Tiago Veloso On

I've solved it, there was an extra * in the modelClassesByResourcePath method:

+ (NSDictionary *)modelClassesByResourcePath {
    return @{
            @"users/*" : [SCUser class],
            @"user/*" : [SCUser class],
            @"card/*" : [SCCreditCard class],
            @"cards" : [SCCreditCard class]
    };
}

All working now.