title: Post multiple Objects with RestKit (as JSON-Array)
body: <p>I'm trying to send multiple objects as an array to a Server with <code>RestKit</code>. Unfortunately I'm not able to do so.<br>
  Following my pretty simple objects as well as the mapping for RestKit:</p>
  
  <h3>Example Objects</h3>
  
  <pre><code>@interface MyExampleObject : NSObject
  
  @property NSString *key;
  @property NSString *value;
  
  @end
  </code></pre>
  
  <h3>Array-Object holding multiple of MyExampleObject</h3>
  
  <pre><code>@interface MyArray : NSObject
  
  @property NSArray *array;
  
  @end
  </code></pre>
  
  <h3>Mapping</h3>
  
  <pre><code>RKObjectMapping *mappingObject = [RKObjectMapping mappingForClass:[MyExampleObject class]];
  [mappingObject addAttributeMappingsFromDictionary:@{
                                                @"key" : @"key",
                                                @"value" : @"value"
                                                }];
  
  RKObjectMapping *mappingArray = [RKObjectMapping mappingForClass:[MyArray class]];
  [mappingArray addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"dummy" toKeyPath:@"array" mappingObject]];
  </code></pre>
  
  <p>If I do it this way I’ll get the following result:</p>
  
  <pre><code>{
    "dummy" : [
      {
        "key" : "MyKey1",
        "value" : "MyValue1"
      },
      {
        "key" : "MyKey2",
        "value" : "MyValue2"
      }
    ]
  }
  </code></pre>
  
  <p>But I want only the array without a „key“. Like this:</p>
  
  <pre><code>[
      {
        "key" : "MyKey1",
        "value" : "MyValue1"
      },
      {
        "key" : "MyKey2",
        "value" : "MyValue2"
      }
  ]
  </code></pre>
  
  <p>It seemed obvious for me to change the <code>relationshipMappingFromKeyPath</code> to <code>nil</code>. But this didn't worked (got a <code>setObjectForKey: key cannot be nil</code> error).</p>
  
  <p>What do I have to do to send multiple <code>MyExampleObjects</code> to my Server as a JSON-Array?</p>
  
  <h2>Solution:</h2>
  
  <p>As <a href="https://stackoverflow.com/users/1988185/wain">Wain</a> suggested I've removed my "Top-Mapping". Following the final mapping:</p>
  
  <pre><code>RKObjectMapping *mappingObject = [RKObjectMapping mappingForClass:[MyExampleObject class]];
  [mappingObject addAttributeMappingsFromDictionary:@{
                                                @"key" : @"key",
                                                @"value" : @"value"
                                                }];
  </code></pre>
  
  <p>And when I post the stuff to my Server I just do something like this:</p>
  
  <pre><code>NSArray *array = [NSArray arrayWithObjects:myExampleObject1, myExampleObject2, nil];
  [[RKObjectManager sharedManager] postObject:array path:@"/myPath/" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
  ...
  }
  </code></pre>