0

I'm stuck on the question of how to build up my objects and mapping to achieve something like this when putting data via the PUT-Method: "lastChanges/confirm"

The above PUT-Request accepts a body like this to confirm synchronization of box ids:

{ "synchronized_boxes": [47292,someOtherBoxId,..] }

I have tried building an Object like this:

@interface RPConfirmSync : NSObject
@property (nonatomic, retain) NSArray *synchronized_boxes;
@end

Before I send this Object I add some NSNumber Objects to the array.

The mapping I set up looks like this:

RKObjectMapping *confirmMapping = [RKObjectMapping mappingForClass:[RPConfirmSync class]];
[confirmMapping addAttributeMappingsFromArray:@[@"synchronized_boxes"]];

RKObjectMapping *requestMapping = [confirmMapping inverseMapping];

NSString *pathPattern = [NSString stringWithFormat:@"lastsync/confirm"];

RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[RPConfirmSync class] rootKeyPath:nil];

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:confirmMapping pathPattern:pathPattern keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[self.objectManager addRequestDescriptor:requestDescriptor];
[self.objectManager addResponseDescriptor:responseDescriptor];

Now, when I execute the above PUT-Request and look at the request body, the RestKit Debug information shows me something weird like this:

request.body=synchronized_boxes[]=47292 //being sent to the server !ERROR!

which should be

request.body=synchronized_boxes[47292]

How do I have to set up my Object or is there something wrong with the mapping? I'm really stuck here, although I guess the answer is straight forward.

helli99
  • 71
  • 1
  • 4
  • 1
    What serialisation have you set? Did you try forcing collection mapping? – Wain Jul 26 '13 at 16:30
  • I tried enabling the "forceCollectionMapping" Flag on the request mapping, but it did not help. – helli99 Jul 29 '13 at 07:35
  • 1
    Check what's actually being sent (using Charles) or received at the server. Check the serialisation type setting. – Wain Jul 29 '13 at 07:46
  • Ok, it was the serialization type set for the request. I did not configure this setting explicitly as JSON because I thought it would use JSON anyways...strange behavior. Now it works! Thank you!!! – helli99 Jul 29 '13 at 10:30

0 Answers0