Reputation: 329
all ...
I've spent all weekend on this and the problem still happens. I don't know what else to do and any help would be very much appreciated. I'm trying to send JSON like this:
{
"proof":
{
"name":"fluff",
"media_type":"Photo",
"description":"This is a description"
},
"auth_token":"mphxNcEGJMJyU7iPmaLw"
}
I keep getting the following exception from RestKit:
2012-07-23 10:29:17.001 restkittest[8389:707] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key auth_token.'
I suspect it's because the auth_token isn't a part of the object (proof) i'm passing, but I don't know how to pass the auth_token along with the proof since postObject only takes one object to post.
... and this is my code to try to do it:
@implementation proof
@synthesize name;
@synthesize description;
@synthesize media_type;
@synthesize duration;
@synthesize frequency_id;
@end
@implementation auth_token
@synthesize auth_token;
@end
- (BOOL)createProof:(proof *)proof
{
BOOL ret = NO;
[self.objectManager postObject:proof usingBlock:^(RKObjectLoader *loader)
{
loader.delegate = self;
RKObjectMapping *proofMappingAccept = [RKObjectMapping mappingForClass:[proof class]];
[proofMappingAccept mapKeyPath:@"name" toAttribute:@"name"];
[proofMappingAccept mapKeyPath:@"description" toAttribute:@"description"];
[proofMappingAccept mapKeyPath:@"media_type" toAttribute:@"media_type"];
[proofMappingAccept mapKeyPath:@"duration" toAttribute:@"duration"];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping mapKeyPath:@"auth_token" toAttribute:@"auth_token"];
[mapping mapKeyPath:@"proof" toRelationship:@"proof" withMapping:proofMappingAccept];
loader.serializationMapping = [mapping inverseMapping];
loader.objectMapping = mapping;
}];
return ret;
}
Upvotes: 1
Views: 156
Reputation: 10633
Create an NSDictionary with your proof object as a value for the key "proof" and your auth_token as an object for the key "auth_token" and set loader.sourceObject to be this dictionary.
Upvotes: 1