Search code examples
iosmappingrestkitmultipart

Send multipart with restkit 0.23.3: response mapping is empty


I am trying to post an object (Walk) to my server.

[[RKObjectManager sharedManager] postObject:walk path:urlPath
                                 parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                                     NSLog(@"It Worked: %@", mappingResult );

                                     if(mappingResult.count==0) {
                                         [self alertStatus:@"Error" :@"Erreur" :0];
                                         return;
                                     }...

The problem is that mappingResult is always empty.

In the log I have the following:

The response:

restkit.object_mapping:RKMapperOperation.m:320 Examining keyPath '<null>' for mappable content...
2015-01-11 22:49:56.250 XXXX restkit.object_mapping:RKMapperOperation.m:300 Found mappable data at keyPath '<null>': {
    errors = "<null>";
    message = success;
    reason = "<null>";
    result = "<null>";
    status = SUCCESS;
}
2015-01-11 22:49:56.251 XXXX D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: {
}
2015-01-11 22:49:56.255 XXXX T restkit.network:RKObjectRequestOperation.m:218 POST 'http://XXXX' (200 OK / 0 objects) [request=2.0944s mapping=0.0100s total=2.1111s]:
response.headers={
    "Cache-Control" = "no-cache, no-store";
    Connection = "Keep-Alive";
    "Content-Type" = "application/json";
    Date = "Sun, 11 Jan 2015 21:48:28 GMT";
    Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
    "Keep-Alive" = "timeout=15, max=99";
    Pragma = "no-cache";
    "Transfer-Encoding" = Identity;
}
response.body={"status":"SUCCESS","message":"success","reason":null,"result":null,"errors":null}
2015-01-11 22:49:56.258  XXXX It Worked: <RKMappingResult: 0x1685b750, results={
        }>

I added this responseDescriptor:

RKResponseDescriptor * descriptor = [RKResponseDescriptor responseDescriptorWithMapping:[ResponseModel defineResponseRequestMapping]
                                             method:RKRequestMethodPOST
                                        pathPattern:nil
                                            keyPath:nil
                                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:descriptor];

I tried with different pathPattern but it's not working. The mapping:

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[ResponseModel class]];

[mapping addAttributeMappingsFromDictionary:@{
                                              @"status":   @"status",
                                              @"reason":   @"reason",
                                              @"message":   @"message",
                                              @"errors":   @"errors",
                                              @"result":   @"result"

                                              }];

Anyone can help me why my mappingResult is always empty even through I have no error from Restkit?

Thank you very much for the help!


Solution

  • Thank you for your message. I just found the solution on this link: RestKit POST response with wrong mapping.

    RestKit use the same mapping for the response than for the request. You have to force it.

    Thank you