I'm trying to map a object through the following JSON:
{
"main_email": {"id": 1, "address": "[email protected]"},
"id": 1,
"first_name": "first name",
"last_name": "last name",
}
I have a object called User with the properties:
@property (nonatomic, assign) NSInteger userID;
@property (nonatomic, copy) NSString *firstName;
@property (nonatomic, copy) NSString *lastName;
@property (nonatomic, strong) Email *mainEmail;
And the object Email have the properties:
@property (nonatomic, assign) NSInteger emailID;
@property (nonatomic, copy) NSString *emailAddress;
Now i'm mapping in the User like bellow:
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping addAttributeMappingsFromDictionary:@{@"id": @"userID",
@"first_name": @"firstName",
@"last_name": @"lastName"}];
RKObjectMapping *emailMapping = [RKObjectMapping mappingForClass:[Email class]];
[emailMapping addAttributeMappingsFromDictionary:@{@"main_email.id": @"emailID",
@"main_email.address": @"emailAddress"}];
[userMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"mainEmail"
toKeyPath:@"mainEmail"
withMapping:emailMapping]];
This code keeps returning a empty Email object in User.mainEmail