title: Mapping json object on coredata entity using RestKIt
body: <p>I am using RestKit for developing some todo list app. I am facing some mapping problem regarding returned json form server with CoreData in iOS. </p>
  
  <p><strong>The Scenario</strong></p>
  
  <p>Following is the image of list and tasks entities which i am using.</p>
  
  <p><img src="https://i.stack.imgur.com/KLAPA.png" alt="enter image description here"></p>
  
  <p>When someone adds a new task to the list on the server i return following Json of that particular list:</p>
  
  <pre><code>`GET www.mydomain.com\api\list\1`
  
          [ { "list" : 
  
            { "listID" : "1",
              "listName" : "New List ",
              "listSyncStatus" : "1"
            },
          "tasks" : [ { "listID" : "1",
                "taskCompletionStatus" : "1",
                "taskID" : "24",
                "taskName" : "Server Added 2",
                "taskSyncStatus" : "1"
              },
              { "listID" : "1",
                "taskCompletionStatus" : "1",
                "taskID" : "25",
                "taskName" : "Server Added 3",
                "taskSyncStatus" : "1"
              },
              { "listID" : "1",
                "taskCompletionStatus" : "1",
                "taskID" : "23",
                "taskName" : "Server Added",
                "taskSyncStatus" : "1"
              }
            ]
        } 
      ]
  </code></pre>
  
  <p>my response descriptor for above json is as follows:</p>
  
  <pre><code>    RKResponseDescriptor *taskResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:taskEntityMapping
                                                                                              method:RKRequestMethodGET
                                                                                         pathPattern:@"/api/list/:id"
                                                                                             keyPath:@"tasks"
                                                                                         statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
  </code></pre>
  
  <p>and for my core data mapping i use following relationship mapping:</p>
  
  <pre><code>    [taskEntityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"list"
                                                                                    toKeyPath:@"list"
                                                                                  withMapping:listEntityMapping]];
  </code></pre>
  
  <p>my <code>taskEntityMapping</code> is as follows:</p>
  
  <pre><code>    NSDictionary *taskObjectMapping = @{
                                      @"listID" : @"listID",
                                      @"taskID" : @"taskID",
                                      @"taskName" : @"taskName",
                                      @"taskCompletionStatus" : @"taskCompletionStatus",
                                      @"taskSyncStatus" : @"taskSyncStatus"
                                  };
  
  RKEntityMapping *taskEntityMapping = [RKEntityMapping mappingForEntityForName:@"Task" inManagedObjectStore:managedObjectStore];
  [taskEntityMapping addAttributeMappingsFromDictionary:taskObjectMapping];
  taskEntityMapping.identificationAttributes = @[ @"taskID" ];
  </code></pre>
  
  <p>and my <code>listEntityMapping</code> is as follows:</p>
  
  <pre><code>    //ALL LISTS RELATED REQUESTS
  NSDictionary *listObjectMapping = @{
                                        @"listID" : @"listID",
                                        @"listName" : @"listName",
                                        @"listSyncStatus" : @"listSyncStatus",
  
                                    };
  
  RKEntityMapping *listEntityMapping = [RKEntityMapping mappingForEntityForName:@"List" inManagedObjectStore:managedObjectStore];
  [listEntityMapping addAttributeMappingsFromDictionary:listObjectMapping];
  
  listEntityMapping.identificationAttributes = @[ @"listID" ];
  </code></pre>
  
  <p>On execution my app crashes with following error 
  <code>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Expected a dictionary representation'</code></p>
  
  <p>and request log is as follows:</p>
  
  <pre><code>2014-02-03 13:17:29.789 RKGist[984:70b] T restkit.network:RKObjectRequestOperation.m:178 GET 'http://mydomain.com/api/list/1':
  request.headers={
      Accept = "application/json";
      "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
      "User-Agent" = "RKGist/1.0 (iPhone Simulator; iOS 7.0.3; Scale/2.00)";
  }
  request.body=(null)
  2014-02-03 13:17:30.670 RKGist[984:f03] T restkit.network:RKResponseMapperOperation.m:451 Mapping HTTP response to nil target object...
  2014-02-03 13:17:30.670 RKGist[984:f03] D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: (
          {
          list =         {
              listID = 1;
              listName = "New List ";
              listSyncStatus = 1;
          };
          tasks =         (
                          {
                  listID = 1;
                  taskCompletionStatus = 1;
                  taskID = 24;
                  taskName = "Server Added 2";
                  taskSyncStatus = 1;
              },
                          {
                  listID = 1;
                  taskCompletionStatus = 1;
                  taskID = 25;
                  taskName = "Server Added 3";
                  taskSyncStatus = 1;
              },
                          {
                  listID = 1;
                  taskCompletionStatus = 1;
                  taskID = 23;
                  taskName = "Server Added";
                  taskSyncStatus = 1;
              }
          );
      }
  )
   and targetObject: (null)
  2014-02-03 13:17:30.671 RKGist[984:f03] T restkit.object_mapping:RKMapperOperation.m:320 Examining keyPath 'tasks' for mappable content...
  2014-02-03 13:17:30.671 RKGist[984:f03] D restkit.object_mapping:RKMapperOperation.m:297 Found mappable collection at keyPath 'tasks': (
          (
                  {
              listID = 1;
              taskCompletionStatus = 1;
              taskID = 24;
              taskName = "Server Added 2";
              taskSyncStatus = 1;
          },
                  {
              listID = 1;
              taskCompletionStatus = 1;
              taskID = 25;
              taskName = "Server Added 3";
              taskSyncStatus = 1;
          },
                  {
              listID = 1;
              taskCompletionStatus = 1;
              taskID = 23;
              taskName = "Server Added";
              taskSyncStatus = 1;
          }
      )
  )
  </code></pre>
  
  <p>the log says found mappable collection at keypath <code>tasks</code>. </p>
  
  <p>Can anyone guide me what am i doing wrong here. Is my returned json format wrong or my mapping code is wrong ? </p>