I’m fetching a user object from a server. If the request succeeds I get:
{ user = {
User = { id = 1; }
} }
On failure I get:
{ user = false; }
I have a mapping that works fine in the success case: [mappingProvider setMapping:userMapping forKeyPath:@"user.User"];
But in the failure case, I get the following exception: 'NSUnknownKeyException', reason: '[<__NSCFBoolean 0x1c58f78> valueForUndefinedKey:]: this class is not key value coding-compliant for the key User.' I also tried setting userMapping as a relationship for keypath User on a mapping to generate an NSDictionary from the user keypath, no joy there either.
What is the correct way to deal with this? It seems like I need two different mappings for the user keypath, and to select which one based on whether on whether the object wants to be decoded to an NSBoolean…
I would suggest
RKDynamicObjectMapping. Either of one of these two flavors should work for you:or