我正在尝试发布一个 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>'
我知道为什么会发生此错误,但不知道解决方案。
这是我的代码,到目前为止我的尝试方式:
请求映射:
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
}];