My backend returns this kind of JSON files:
{ "response": { "message": "Test" }, "responseCode": 205 }
Depending on responseCode value, what is inside response is different. I know I have to use something like RKDynamicMapping, but not sure how. The problem I see is that in the sample code and manual, the attribute to differentiate among mappings is inside, but in this case is outside. I tried this but doesn't work:
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
NSNumber* responseCode=(NSNumber*)representation[@"responseCode"];
if (responseCode.integerValue==204) {
return searchByLocatorResponseContent204Mapping;
} else if (responseCode.integerValue==205) {
return searchByLocatorResponseContent205Mapping;
}
return nil;
}];
RKResponseDescriptor *searchByLocatorResponseContentResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:kCheckinSearchByLocatorPath keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:searchByLocatorResponseContentResponseDescriptor];
I guess because the mapping I want to change doesn't containt the attribute to distinguish them (like type in girls/boys sample code from rest kit website)
Does anyone have any recommendation? Thanks in advance.