How to auto map to mantle model class in case of envelop response with overcoat?

342 views Asked by At

I am using mantle for model mapping and overcoat for network request. Overcoat auto map the result to model, but when there is envelope response, I am able to get custom Overcoat response. But problem is the Overcoat response is NSCFDictionary response, but it is supposed to be MantleModel response.

return [RACSignal createSignal: ^RACDisposable *(id<RACSubscriber> subscriber){
  [[client rac_GET:@"/services" parameters:@{@"location": @"lat,lng"}] subscribeNext:^( OvercoatResponse *response){
    NSArray *res = response.result;//res[0] is _NSCFDictionary object, but it should be MantleModel Object
    [subscriber sendNext:res];
  } error:^(NSError *error) {
    NSLog(@"ERROR: %@", error);
  }
   ];
  return nil;
}];

I know how to manually transform the result into mantleModel:

 NSArray *mtlnArray = [MTLJSONAdapter modelsOfClass:[MantleModel class] fromJSONArray:response.result error:&error];

But it should be done by overcoat for me. I am curios is there anyway to do it via Overcoat instead of manually transforming the result.

1

There are 1 answers

0
Rapture Alcatraz On

Refer to README.md:

To specify how responses should be mapped to model classes you must override +modelClassesByResourcePath and return a dictionary mapping resource paths to model classes.

example:

// TwitterClient.h

@interface TwitterClient : OVCHTTPSessionManager

// TwitterClient.m

+ (NSDictionary *)modelClassesByResourcePath {
    return @{ @"statuses/*": [Tweet class],
              @"users/*": [TwitterUser class],
              @"friends/ids.json": [UserIdentifierCollection class],
              @"followers/ids.json": [UserIdentifierCollection class]};
}

P.S. responseSerializer has been automatically setup when initWithBaseURL.. , if you reset again, it probably would fail.