title: RestKit 0.20 NSArray serialization problems
body: <p>I'm trying to serialize an NSArray of objects.</p>
  
  <p>The object serializes as:</p>
  
  <pre><code>{"age":1,"name":"Foo"}
  </code></pre>
  
  <p>If I have an NSArray Containing these objects, it should serialize as:</p>
  
  <pre><code>[{"age":1,"name":"Bob"},{"age":4,"name":"Sally"},{"age":2,"name":"Jill"}]
  </code></pre>
  
  <p>However, when I serialize it directly via RestKit, I get the following:</p>
  
  <pre><code>{"age":[1,3,2],"name":["Sally","Jack","Bob"]}
  </code></pre>
  
  <p>When I inspect the RKMIMETypeSerialization, I see the following: (which would match the json output)</p>
  
  <pre><code>Parameters: {
      age =     (
          1,
          3,
          2
      );
      name =     (
          Sally,
          Jack,
          Bob
      );
  }
  </code></pre>
  
  <p>I'm sure that I'm just doing something really silly, I have been playing with it can't figure it out.</p>
  
  <p>Here is my mapping logic</p>
  
  <pre><code>+ (RKObjectMapping *)mapping {
      RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Item class]];
      [mapping addAttributeMappingsFromDictionary:@{
              @"name" : @"name",
              @"age" : @"age"
      }];
  
      return mapping;
  }
  </code></pre>
  
  <p>And here is the logic doing the array serialization:</p>
  
  <pre><code>+ (NSString *)JSONStringFromArray:(NSArray *)array {
      RKObjectMapping *mapping = [Item mapping];
      RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping.inverseMapping objectClass:[Item class] rootKeyPath:nil];
      NSError *error;
      NSDictionary *parameters = [RKObjectParameterization parametersWithObject:array requestDescriptor:requestDescriptor error:&amp;error];
  
  // Serialize the object to JSON
      NSData *JSON = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&amp;error];
  
      NSString *jsonString = [[NSString alloc] initWithBytes:[JSON bytes]
                                                      length:[JSON length] encoding:NSUTF8StringEncoding];
      return jsonString;
  }
  </code></pre>
  
  <p>Here are test classes:
  <strong>Item.h</strong></p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @interface Item : NSObject
  @property(nonatomic, strong) NSString *name;
  @property(nonatomic) int age;
  
  + (void)testJsonSerialization;
  
  + (void)testJsonArraySerialization;
  
  + (Item *)itemWithName:(NSString *)string age:(int)age;
  @end
  </code></pre>
  
  <p><strong>Item.m</strong></p>
  
  <pre><code>#import "Item.h"
  #import &lt;RestKit.h&gt;
  
  @implementation Item
  + (RKObjectMapping *)mapping {
      RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Item class]];
      [mapping addAttributeMappingsFromDictionary:@{
              @"name" : @"name",
              @"age" : @"age"
      }];
  
      return mapping;
  }
  
  - (NSString *)JSONString {
      RKObjectMapping *mapping = [Item mapping];
      RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping.inverseMapping objectClass:[Item class] rootKeyPath:nil];
      NSError *error;
      NSDictionary *parameters = [RKObjectParameterization parametersWithObject:self requestDescriptor:requestDescriptor error:&amp;error];
  
  // Serialize the object to JSON
      NSData *JSON = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&amp;error];
  
      NSString *jsonString = [[NSString alloc] initWithBytes:[JSON bytes]
                                                      length:[JSON length] encoding:NSUTF8StringEncoding];
      return jsonString;
  }
  
  + (NSString *)JSONStringFromArray:(NSArray *)array {
      RKObjectMapping *mapping = [Item mapping];
      RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping.inverseMapping objectClass:[Item class] rootKeyPath:nil];
      NSError *error;
      NSDictionary *parameters = [RKObjectParameterization parametersWithObject:array requestDescriptor:requestDescriptor error:&amp;error];
  
  // Serialize the object to JSON
      NSData *JSON = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&amp;error];
  
      NSString *jsonString = [[NSString alloc] initWithBytes:[JSON bytes]
                                                      length:[JSON length] encoding:NSUTF8StringEncoding];
      return jsonString;
  }
  
  + (void)testJsonSerialization {
      Item *item = [Item itemWithName:@"Foo" age:1];
      NSString *itemJSON = [item JSONString];
      NSLog(@"ItemJSON:\n%@\n\n", itemJSON);
  }
  
  + (void)testJsonArraySerialization {
      NSArray *items = @[[Item itemWithName:@"Sally" age:1], [Item itemWithName:@"Jack" age:3], [Item itemWithName:@"Bob" age:2]];
      NSString *itemJSON = [Item JSONStringFromArray:items];
      NSLog(@"ItemArrayJSON:\n%@\n\n", itemJSON);
  }
  
  + (Item *)itemWithName:(NSString *)name age:(int)age {
      Item *item = [[Item alloc] init];
      item.name = name;
      item.age = age;
      return item;
  }
  @end
  </code></pre>
  
  <p><strong>To execute</strong>
  Have RestKit pod installed and then issue the following:</p>
  
  <pre><code>    [Item testJsonSerialization];
      [Item testJsonArraySerialization];
  </code></pre>
  
  <p>Note, maybe I'm not configuring the mapping correctly for the array serialization.  Though this mapper works perfectly for deserializing the targeted json text up above.</p>