我想發佈一個object1(託管對象)並接收另一個object2(不是託管對象)。 我收到以下錯誤: W restkit.object_mapping:RKMapperOperation.m:98 Adding mapping error: Expected an object mapping for class of type '<object1 class>', provider returned one for '<object2 class>'
RestKit 0.20命名的發佈請求
我知道爲什麼會發生此錯誤,但不知道解決方案。
這裏是我的代碼,我是怎麼到目前爲止嘗試:
請求映射:
RKObjectMapping *objectMapping = [RKObjectMapping requestMapping];
[objectMapping addAttributeMappingsFromArray:@[@"prop1", @"prop2", @"prop3"]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:objectMapping objectClass:[<object1 class> class] rootKeyPath:nil];
[[RKObjectManager sharedManager] addRequestDescriptor:requestDescriptor];
響應映射:
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[<object2 class> class]];
[objectMapping addAttributeMappingsFromArray:@[@"prop4", @"prop5"]];
responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:objectMapping pathPattern:@"myPattern" keyPath:@"" statusCodes:statusCodes];
[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];
路由:
[[RKObjectManager sharedManager].router.routeSet addRoute:[RKRoute routeWithClass:[<object1 class> class] pathPattern:@"myPattern" method:RKRequestMethodPOST]];
召喚:
[[RKObjectManager sharedManager] postObject:object1 path:nil parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
// Success
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
// Fail
}];
好了,但在這種情況下,將RestKit做解析,而不是我? –
是的,因爲您在創建響應操作時指定了響應描述符。 – Wain
但基礎網址和其他網址相關的東西不能被使用? –