I'd say your best bet is to create a response descriptor with a key path of @"results"
and a dynamic mapping. That mapping would return a mapping which maps into an NSDictionary
and which has a number of relationships defined. This dictionary is just a container to facilitate the other mappings (the relationships).
The relationships are created by iterating the keys of the representation provided to the dynamic mapping and creating one relationship per iteration, using the testMapping
, but without the addAttributeMappingFromKeyOfRepresentationToAttribute
as you can now use direct attribute access (and the inner type
attribute).
Using setObjectMappingForRepresentationBlock:
, your block is provided with the representation
, which in your case is an NSDictionary
of the deserialised JSON. Inside the block you create a mapping just as you usually would, but with the contents based on the keys in the dictionary.
RKObjectMapping *testMapping = [RKObjectMapping mappingForClass:[Test class]];
[testMapping addAttributeMappingsFromDictionary:@{ @"id": @"testId", @"name": @"testName" }];
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
RKObjectMapping *testListMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
for (NSString *key in representation) {
[testListMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeypath:key toKeyPath:key withMapping:testMapping];
}
return testListMapping;
}];