title: Restkit object mapping with multiple root objects
body: <p>I have a web service that returns a JSON in the following format: </p>
  
  <pre><code>{
  "client": {
           "firstName": "Aaron"
           },
  "error": {
           "code":""
           }
  }
  </code></pre>
  
  <p>And I am having setting up the mapping in restkit. I keep getting the following error:</p>
  
  <p><code>Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "Could not find an object mapping for keyPath: ''" UserInfo=0x5961f0 {=RKObjectMapperKeyPath, NSLocalizedDescription=Could not find an object mapping for keyPath: ''}</code></p>
  
  <p>Here is how I am setting up the mappings:</p>
  
  <pre><code>    [[RKObjectManager sharedManager].mappingProvider setMapping:[Client objectMapping] forKeyPath:@"client"];
      [[RKObjectManager sharedManager].mappingProvider setMapping:[ErrorObject objectMapping] forKeyPath:@"error"];
  </code></pre>
  
  <p>Client Mapping:</p>
  
  <pre><code>+(RKObjectMapping*) objectMapping {
     RKObjectMapping* responseObjectMapping = [RKObjectMapping mappingForClass:[Client class]];
     [responseObjectMapping setRootKeyPath:@"client"];
     [responseObjectMapping mapKeyPathsToAttributes:
      @"firstName", @"firstName",
      nil];
     return responseObjectMapping;
  }
  </code></pre>
  
  <p>Error Mapping:</p>
  
  <pre><code>+(RKObjectMapping*) objectMapping {
     RKObjectMapping* responseObjectMapping = [RKObjectMapping mappingForClass:[ErrorObject class]];
     [responseObjectMapping setRootKeyPath:@"error"];
     [responseObjectMapping mapKeyPathsToAttributes:
      @"code", @"code",
      nil];
     return responseObjectMapping;
  }
  </code></pre>
  
  <p>And calling the service like this:</p>
  
  <pre><code>//Send initial load request
  [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/getdetails" stringByAppendingQueryParameters:params] usingBlock:^(RKObjectLoader *loader) {
      loader.delegate = self;
      loader.userData = INITIAL_LOAD_REQUEST;
  }];
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I fixed my problem by following advice below and also moving my mapping from the init method to setting it in the object loader block like this: </p>
  
  <pre><code>    //Send initial load request
  [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/getdetails" stringByAppendingQueryParameters:params] usingBlock:^(RKObjectLoader *loader) {
      loader.delegate = self;
  
      //set mapping explicitly
      RKObjectMappingProvider *provider = [[RKObjectMappingProvider alloc] init];
      [provider setMapping:[Clien objectMapping] forKeyPath:@"client"];
      [provider setMapping:[ErrorObject objectMapping] forKeyPath:@"error"];
      [loader setMappingProvider:provider];
  
      loader.userData = INITIAL_LOAD_REQUEST;
  }];
  </code></pre>