I want to post a request with User
object to register but I am getting this error:
The mapping operation was unable to find any nested object representations at the key paths searched
Here is my code for posting the request:
User * user = [[User alloc]init];
user.UserName = _userNameTextField.text;
user.Password = _passwordTextField.text;
user.ConfirmPassword = _passwordTextField.text;
user.Email = _emailTextField.text;
// {
// "Email": "sample string 1",
// "UserName": "sample string 2",
// "Password": "sample string 3",
// "ConfirmPassword": "sample string 4"
// }
RKObjectManager * objectmanager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"url"]];
RKObjectMapping * userMapping = [RKObjectMapping requestMapping];
[userMapping addAttributeMappingsFromArray:@[@"Email",@"UserName",@"Password",@"ConfirmPassword"]];
RKRequestDescriptor * registrationDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:userMapping objectClass:[User class] rootKeyPath:@"api/Account/Register/" method:RKRequestMethodPOST];
[objectmanager addRequestDescriptor:registrationDescriptor];
[objectmanager postObject:user path:@"api/Account/Register/" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"Success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Fail");
}];
Any help is extremely appreciated.
Solution
The solution was to delete the root key path.
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
You will see additional information in console.