2

I'm new to RestKit and Objective C. I'm trying to retrieve data from a Web Service with RestKit. I have done the mapping but some how I'm getting the error that it could not find a match for the response. I am using Mapping without KVC as the JSON format has no key.

Here is the mapping implementation

+(RKObjectMapping *)venueMapping {
     RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[venue class]];
     NSDictionary *mappingDictionary = @{@"name":@"name"};
    [mapping addAttributeMappingsFromDictionary:mappingDictionary];

    return mapping;
 } 

I am trying with only one value to see if anything matches. Below is the response descriptor

-(void) loadVenue:(void (^)(venue *))success failure:(void (^)(RKObjectRequestOperation *, NSError *))failure{

     RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
     [self getObjectsAtPath:@"venue" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){

    if(success){
        venue *venues = (venue *)[mappingResult.array firstObject];
        success(venues);
    }

    }failure:^(RKObjectRequestOperation *operation, NSError *error){
        if(failure){
           failure(operation,error);
    }
}];

}

- (void) setupResponseDescriptors {
[super setupResponseDescriptiors];

RKResponseDescriptor *authenticatedUserResponseDescriptors = [RKResponseDescriptor responseDescriptorWithMapping:[MappingProvider venueMapping] method:RKRequestMethodGET pathPattern:@"venue" keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self addResponseDescriptor:authenticatedUserResponseDescriptors];
}

I have been reading the documentation and trying out various ways, but I have still zero solution for this. Anyone has any idea?

Attached is a sample JSON return.

 (
    {
    coverType = "<null>";
    description = "";
    name = "McDonald";
    priv = 1;
    rates = ();
    },
    {
    coverType = "<null>";
    description = "";
    name = "My House";
    priv = 1;
    rates =();
    },
 )

Added TraceLog

2014-04-22 21:45:55.636 App_Test[420:60b] I restkit:RKLog.m:34 RestKit logging initialized...
2014-04-22 21:45:56.064 App_Test[420:60b] I restkit.network:RKObjectRequestOperation.m:180 GET 'http://api.kontakt.io/venue'
2014-04-22 21:46:46.327 App_Test[420:f03] D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: (
        {
        beacons =         (
        );
        beaconsCount = 0;
        coverType = "<null>";
        description = "";
        id = "212321";
        lat = "<null>";
        lng = "<null>";
        managers =         (
        );
        name = McDonald;
        priv = 1;
        rates =         (
        );
        users =         (
        );
    }
)
 and targetObject: (null)
2014-04-22 21:46:46.328 App_Test[420:f03] D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: (null)
2014-04-22 21:46:46.328 App_Test[420:570b] E restkit.network:RKObjectRequestOperation.m:243 GET 'http://api.kontakt.io/venue' (200 OK / 0 objects) [request=0.9645s mapping=0.0000s total=50.3422s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x9556ab0 {NSErrorFailingURLStringKey=http://api.kontakt.io/venue, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://api.kontakt.io/venue', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://api.kontakt.io/venue, NSUnderlyingError=0x9557c30 "No mappable object representations were found at the key paths searched."}
greenhatman
  • 76
  • 1
  • 7
  • I tried to put the entire mapping in the code, in case it's not mapping correctly due to insufficient data. But seems like it's still not working. However, I found this error during debug, **NSUnderlyingError: Summary string parsing error**. Does this mean that there is some issue with my mapping declarations? – greenhatman Apr 21 '14 at 06:57
  • After further debugging, it seems like the baseURL did not match. Not too sure what's going on. Will try to further debug – greenhatman Apr 21 '14 at 07:38
  • Can you add the trace log output for the response? And change the response descriptor key path to `nil`. – Wain Apr 22 '14 at 09:46
  • @Wain I have added the tracelog output and also changed the response descriptor key path to nil. Still not getting anywhere near to the solution – greenhatman Apr 22 '14 at 13:31
  • Based on that log it appears that `setupResponseDescriptors` is never being called... – Wain Apr 22 '14 at 13:38
  • @Wain You are right! I checked back the code and made sure it was linking and woila it works now! Thanks much! – greenhatman Apr 22 '14 at 15:06

3 Answers3

4

The error message says:

which failed to match all (0) response descriptors

This indicates (due to the (0) in the message) that the setupResponseDescriptors method is not being called so no response descriptors are being added to the object manager.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Thank you @Wain! I was thinking that it could be mapping was wrongly defined or something but apparently it wasn't called in the objectManager due to mismatch naming. Silly me. – greenhatman Apr 23 '14 at 02:11
0

You are attempting to get object at path "venue", but there doesn't appear to be any indication that you have a "venue" object in your JSON.

benuuu
  • 761
  • 2
  • 7
  • 24
  • Not sure if I'm reading this correctly, but according to the docs `many web API's return their JSON without any nesting attributes that can be used for mapping selection. In these cases you can still work with RestKit, you just have to rely upon the use of URL matching.` That's why I'm using the path pattern as mentioned in the docs – greenhatman Apr 20 '14 at 14:06
0

If you are not using CoreData, be sure Restkit is defined in your Podfile as follows

pod 'RestKit/Network', '~> 0.23' pod 'RestKit/ObjectMapping', '~> 0.23'

Gaston Morixe
  • 839
  • 2
  • 10
  • 21