I'm trying to process a rest response containing a nested dictionary using RestKit 0.20. here is the json response that I'm trying to process:
{
"name": "Tom",
"msgTo": "Hi ",
"msgFrom": "Hey",
"uuid": "4",
"ClientInfo": {
"Tom": {
"AttributeA": "0",
"AttributeB": "28"
},
"Sam": {
"AttributeA": "10",
"AttributeB": "28"
}
}
}
The issue is around the ClientInfo object. This object is a serialized java map of maps [ Map>] from the server using pojo jackson serialization.
here are the 2 models in iOS/RestKit I'm using to process the response:
@interface IAPClientInfo : NSObject
@property (weak, nonatomic) NSString * mapName;
@property (weak,nonatomic) NSString *propertyCount;
@property (weak,nonatomic) NSString *affinityValue;
@end
@interface IAPClientMessage : NSObject
@property (weak, nonatomic) NSString * name;
@property (weak, nonatomic) NSString * msgTo;
@property (weak, nonatomic) NSString * msgFrom;
@property (weak, nonatomic) NSString * uuid;
// should this be an array?
@property (weak, nonatomic) NSArray * iapClientInfoArray;
@end
here is the code
// inner mapping
RKObjectMapping *clientInfoMapping = [RKObjectMapping mappingForClass:[IAPClientInfo class]];
[clientInfoMapping setForceCollectionMapping:YES];
[clientInfoMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"mapName"];
[clientInfoMapping addAttributeMappingsFromDictionary:@{@"(mapName).AttributeA" : @"propertyCount", @"(mapName).AttributeB" : @"affinityValue"}];
// outer mapping
RKObjectMapping *messageMapping = [RKObjectMapping mappingForClass:[IAPClientMessage class]];
[messageMapping addAttributeMappingsFromDictionary:@{@"msgFrom" : @"msgFrom",@"msgTo" : @"msgTo",@"uuid" : @"uuid",@"name" : @"name"}];
// relationship b/w inner and outer
RKRelationshipMapping *relationshipMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"ClientInfo" toKeyPath:@"iapClientInfoArray" withMapping:clientInfoMapping];
[messageMapping addPropertyMapping:relationshipMapping];
// response
RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:messageMapping
pathPattern:nil
keyPath:@""
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptor];
When processing the response, the properties in the IAPClientMessage are all as expected except the iapClientInfoArray property, which is null. While there are mutiple IAPClientInfo objects, in the json response it's not clear what the property should be in the IAPClientMessage (currently set to NSArray*). Any suggestions to make this work properly?
tx.