Reputation: 1491
I am using Restkit to post an object of type A and the response should be an object of type B.
I set up the appropriate response and request mappings, but RestKit is complaining that it got an object of type B instead of A.
Since this is the behavior I want, is there a way to tell RestKit that its ok and to go ahead and map it for me?
Upvotes: 2
Views: 295
Reputation: 1163
In the RKObjectManager, line 668, you can comment out this if conditional:
if (RKDoesArrayOfResponseDescriptorsContainMappingForClass(self.responseDescriptors, [object class])) operation.targetObject = object;
FYI: Make sure to use explicit path's in your postObject call, or restkit will grab the first response descriptor it finds.
Restkit normally (with out this line commented out) will just use the targetObject instead of using the response descriptor that is associated with the path sent for the postObject.
Upvotes: 0
Reputation: 119041
You need to do some extra work to tell RestKit that the source object for the POST should not be used as the target object. To do this you need to nil
the targetObject
of the request operation (which means explicitly getting the operation in the first place and then enqueueing it):
RKManagedObjectRequestOperation *operation = [objectManager appropriateObjectRequestOperationWithObject:objectToPost method:RKRequestMethodPOST path:@"XXX" parameters:anyParams];
operation.targetObject = nil;
operation.targetObjectID = nil;
[objectManager enqueueObjectRequestOperation:operation];
Upvotes: 5