I am trying to read data from server using RestKit 0.20 in my iOS app and getting the following error :
//Error
`… I restkit:RKLog.m:34 RestKit logging initialized...`
`… I restkit.support:RKMIMETypeSerialization.m:115 JSON Serialization class 'RKNSJSONSerialization' detected: Registering for MIME Type 'application/json`
`... T restkit.network:RKHTTPRequestOperation.m:139 GET '(null)':
request.headers={
Accept = "application/json";
"Accept-Language" = "en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8";
"User-Agent" = "XXXXX/1.0 (iPhone Simulator; iOS 5.0; Scale/1.00)";
}
request.body=(null)`
`... E restkit.network:RKHTTPRequestOperation.m:150 GET '(null)' (0):
error=Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x6c9d570 {NSUnderlyingError=0x6c9d460 "bad URL", NSLocalizedDescription=bad URL}
response.body=(null)`
`... E restkit.network:RKObjectRequestOperation.m:270 Object request failed: Underlying HTTP request operation failed with error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x6c9d570 {NSUnderlyingError=0x6c9d460 "bad URL", NSLocalizedDescription=bad URL}`
`... Hit error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x6c9d570 {NSUnderlyingError=0x6c9d460 "bad URL", NSLocalizedDescription=bad URL}`
Here is the JSON received from server:
[ {
"array1" : [ {
"a1prop1" : 1,
"a1prop2" : "prop21val",
}, {
"a1prop1" : 2,
"a1prop2" : "prop22val",
}, {
"a1prop1" : 3,
"a1prop2" : "prop23val",
} ],
"property1" : prop1val,
"property2" : "prop2val",
"property3" : "prop3val",
} ]
Mappings using RestKit:
-(void) getData {
………………...
NSURL *baseURL = [NSURL URLWithString:stringURL];
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[client setDefaultHeader:#"Accept" value:RKMIMETypeJSON];
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
[objectManager setAcceptHeaderWithMIMEType:RKMIMETypeJSON];
RKObjectMapping *array1Mapping = [RKObjectMapping mappingForClass:[ArrayOneClass class]];
[array1Mapping addAttributeMappingsFromDictionary:#{
#"a1Prop1" : #"a1Prop1",
#"a1Prop2" : #"a1Prop2",
}];
RKObjectMapping *mainObjectMapping = [RKObjectMapping mappingForClass:[MainObjectClass class]]
[mainObjectMapping addAttributeMappingsFromDictionary:#{
#"property1" : #"property1",
#"property2" : #"property2",
#"property3" : #"property3",
}];
RKRelationshipMapping *mainObjRelationMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:#"array1" toKeyPath:#"array1" withMapping:array1Mapping];
[mainObjectMapping addRelationshipMappingWithSourceKeyPath:#"array1" mapping: mainObjRelationMapping.mapping];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mainObjectMapping pathPattern:nil
keyPath:nil
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:responseDescriptor];
NSString *pathStr = [NSString stringWithFormat:#"/api/getAllObjects"];
[objectManager getObjectsAtPath:pathStr
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"...success");
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"Hit error: %#", error);
}];
}
MainObject Class:
//MainObjectClass.h
#interface MainObjectClass : NSObject{
int property1;
NSString * property2;
NSString * property3;
NSSet *array1;
}
#property (nonatomic) int property1;
#property (nonatomic, retain) NSString * property2;
#property (nonatomic, retain) NSString * property3;
#property (nonatomic, retain) NSSet *array1;
- (NSDictionary*)elementToPropertyMappings;
- (NSDictionary*)elementToRelationshipMappings;
#end
//MainObjectClass.m
#implementation MainObjectClass
#synthesize property1, property2, property3, array1;
- (NSDictionary*)elementToPropertyMappings {
return [NSDictionary dictionaryWithObjectsAndKeys:
#"property1", #"property1",
#"property2", #"property2",
#"property3", #"property3",
nil];
}
- (NSDictionary *)elementToRelationshipMappings {
return [NSDictionary dictionaryWithObjectsAndKeys:
#"array1", #"array1",
nil];
}
#end
Can anyone please tell me why this is not generating proper request? It is not hitting the server at all. I tried simple get/post methods with no relationship mappings and they all are working fine with RestKit mappings. Appreciate your views. Thanks.
try this :- use property of RKObjectManager
objectManager.serializationMIMEType = RKMIMETypeJSON;
Related
I'm experiencing Restkit, using the version 0.25.0. I followed exactly what the documentation says for the relationship mapping, but for some reasons, I have an empty mapping result !
But when I remove the relationship object (data), I have a mapping result !!! But of course, the mapping result doesn't contain the data I need, the one I added as relationship.
I followed the example they have in this link :
https://github.com/RestKit/RestKit/wiki/Object-mapping#relationships
When I print the JSON with the debugger, here's the output :
{
"status": "success",
"data": {
"id": 11,
"provider": "email",
"uid": "riri#gmail.com",
"name": null,
"nickname": null,
"image": null,
"email": "riri#gmail.com",
"country": "United States",
"city": "Milan, Metropolitan City of Milan, Italy",
"gender": "m",
"birthday": "2015-06-25"
}
}
Here's the code how I make the request :
RKObjectManager *manager = [RKObjectManager sharedManager];
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKObjectMapping *jsonResponseMapping = [JSONResponse mappingObject];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:jsonResponseMapping
method:RKRequestMethodAny
pathPattern:#"/auth/sign_in"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptor:responseDescriptor];
NSDictionary *parameters = #{
#"email": user.email,
#"password": user.password
};
[manager postObject:user path:#"/auth/sign_in" parameters:parameters success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSDictionary *headerFields = operation.HTTPRequestOperation.response.allHeaderFields;
[self updateUserInfoForResponse:[mappingResult firstObject] headerFields:headerFields];
if (successBlock) {
successBlock([mappingResult firstObject]);
}
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
if (failureBlock) {
failureBlock(error.userInfo[RKObjectMapperErrorObjectsKey][0], error);
}
}];
.m of JSONResponse class:
+ (RKObjectMapping *)mappingObject {
RKObjectMapping *jsonResponseMapping = [RKObjectMapping mappingForClass:[JSONResponse class]];
[jsonResponseMapping addAttributeMappingsFromDictionary:#{
#"status": #"status",
#"errors": #"errors",
}];
RKRelationshipMapping *userRelationShip = [RKRelationshipMapping relationshipMappingFromKeyPath:#"data" toKeyPath:#"data" withMapping:[User mappingObject]];
[jsonResponseMapping addPropertyMapping:userRelationShip];
return jsonResponseMapping;
}
.h Of JSONResponse class :
#import <RestKit/Restkit.h>
#import <Foundation/Foundation.h>
#import "User.h"
#interface JSONResponse : NSObject
#property (nonatomic, copy) NSString *status;
#property (nonatomic) User *data;
#property (nonatomic, copy) NSDictionary *errors;
/**
#function mappingObject
#return RKObjectMapping mapping for the json response
*/
+ (RKObjectMapping *)mappingObject;
#end
.m of User class
#import "User.h"
#implementation User
+ (RKObjectMapping *)mappingObject {
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping addAttributeMappingsFromDictionary:#{
#"email": #"email",
#"password": #"password",
#"gender": #"gender",
#"birthday": #"dateOfBirth",
#"city": #"city",
#"country": #"country"
}];
return userMapping;
}
#end
.h of User class
#class RKObjectMapping;
#interface User : NSObject
#property (nonatomic, copy) NSString *email;
#property (nonatomic, copy) NSString *password;
#property (nonatomic, copy) NSString *gender;
#property (nonatomic, copy) NSString *dateOfBirth;
#property (nonatomic, copy) NSString *city;
#property (nonatomic, copy) NSString *country;
/**
#function mappingObject
#return RKObjectMapping mapping object for user
*/
+ (RKObjectMapping *)mappingObject;
#end
Is there anything wrong in my models objects ? The relationship is set properly right ? I do have the data property in the JSONResponse, and the JSON contains correctly the keyPath data.
So I'm pretty confused why I have results when I remove my relationship, and why the mapping result is empty when I have the relationship. It's even doesn't go in the failureCallback, the operation is successful, the result is empty.
Any ideas ??
EDIT :
Here's the logs :
2015-09-15 07:27:50.649 testRestkit[53698:3448725] D restkit.object_mapping:RKPropertyInspector.m:154 Cached property inspection for Class 'JSONResponse': {
data = "<RKPropertyInspectorPropertyInfo: 0x7facf2c5fa00>";
status = "<RKPropertyInspectorPropertyInfo: 0x7facf2c5f7d0>";
}
2015-09-15 07:27:50.650 testRestkit[53698:3448725] D restkit.object_mapping:RKPropertyInspector.m:154 Cached property inspection for Class 'User': {
email = "<RKPropertyInspectorPropertyInfo: 0x7facf2c60680>";
}
2015-09-15 07:27:50.820 testRestkit[53698:3448725] I restkit.network:RKObjectRequestOperation.m:150 POST 'http://sandrotchikovani.com/test.php'
2015-09-15 07:27:51.236 testRestkit[53698:3448938] D restkit.object_mapping:RKMapperOperation.m:407 Executing mapping operation for representation: {
data = {
email = "lol#gmail.com";
};
status = success;
}
and targetObject: <User: 0x7facf2c05820>
2015-09-15 07:27:51.237 testRestkit[53698:3448938] T restkit.object_mapping:RKMapperOperation.m:350 Examining keyPath '<null>' for mappable content...
2015-09-15 07:27:51.237 testRestkit[53698:3448938] D restkit.object_mapping:RKMapperOperation.m:330 Found mappable data at keyPath '<null>': {
data = {
email = "lol#gmail.com";
};
status = success;
}
2015-09-15 07:27:51.237 testRestkit[53698:3448938] D restkit.object_mapping:RKMapperOperation.m:433 Finished performing object mapping. Results: {
}
Isn't weird that in the log, it says and targetObject: <User: 0x7facf2c05820> ? When I remove the relationship, there is a mapping result and the targetObject, displays "null".
You are calling postObject:..., and when you do that RestKit will map back to the original object. In this case that's a user and that's why you're seeing the log and targetObject: <User: 0x7facf2c05820>.
The easiest thing for you to do is to setup your JSONResponse so that you post it and receive the response into it. It already has the required user so a simple change to the request descriptor to pull out the user fields should be enough.
Alternatively there are a bunch of other questions about mapping to a different object after posting.
Given the following JSON structure:
{
"foo": {
"anno": "blah",
"domini": null,
"locations": [
{
"data": {
"lat": null,
"lon": null
},
"data": {
"lat": null,
"lon": null
}
}
]
}
}
How do I set up RestKit mappings for this scenario? I though I had it, but I'm unable to map the top-level foo items anno, and domini. I can successfully map locations on its own, but not in coordination with foo.
I've done this successfully in the past, but something is escaping me now.
Foo.h
#interface Foo : NSObject
#property (nonatomic, strong) NSString *anno;
#property (nonatomic, strong) NSString *domini;
#end
Location.h
#interface LocationData : NSObject
#property NSString *lat;
#property NSString *lon;
#end
Controller.m
RKObjectMapping *fooMapping = [RKObjectMapping mappingForClass:[Foo class]];
[fooMapping addAttributeMappingsFromArray:#[#"anno", #"domini"]];
RKObjectMapping *locationMapping = [RKObjectMapping mappingForClass:[Location class]];
[locationMapping addAttributeMappingsFromArray:#[#"lat",#"lon"]];
[fooMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"location" toKeyPath:#"location" withMapping: locationMapping]];
RKResponseDescriptor *fooReponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dataMapping method:RKRequestMethodGET pathPattern:#"foo" keyPath:#"foo" statusCodes:[NSIndexSet indexSetWithIndex:200]];
RKResponseDescriptor *locationResponseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:locationdMapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:#"foo.location"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
I think that's all of the important stuff. Hopefully in my zeal to pare down how much text I was posting I didn't leave anything important out.
EDIT 2015-03-29
- (void)loadChildren {
NSDictionary *queryParams = #{#"sort" : #"new"};
[[RKObjectManager sharedManager] getObjectsAtPath:redditPath
parameters:queryParams
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
_children = mappingResult.array;
[self.tableView reloadData];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"You mean YOU'RE the lunatic who's responsible for almost destroying my ship? : %#", error);
}];
}
redditpath is set earlier using...
redditPath = [NSString stringWithFormat:#"/r/%#/new.json", subRedditToLoad];
Where subRedditToLoad is, in this case, aww.
In your XCDataModel Take an Entity with named Foo.
Set Property of anno and vomini.
Also Create another Entity Location.
Set a property named data with type Transformable.
Add Relationship at Foo for Location entity put it many relationship.
Call mapping for Foo Like:
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"foo" toKeyPath:#"Foo" withMapping:[Location objectMappingForLocation:Enum]]];
This is the json that I need to post to services.
{
"deviceToken":"asdfasdfasdf",
"alarm": [
{
"start" "8:30",
"end": "9:30",
"line": "156",
"code": "xxxafsdfasdf",
"station": "asdfa",
"stationLeft": 5,
"available": true,
"times": 2
}]
}
The response data just have one more field "id" in alarm:
{
"deviceToken":"asdfasdfasdf",
"alarm": [
{
"id":1,
"start" "8:30",
"end": "9:30",
"line": "156",
"code": "xxxafsdfasdf",
"station": "asdfa",
"stationLeft": 5,
"available": true,
"times": 2
}]
}
Then I define two objects:
DeviceAlarm Object:
#interface DeviceAlarm : NSObject
#property(nonatomic, strong) NSMutableArray *alarm;
#property(nonatomic, copy) NSString *deviceToken;
#end
Alarm Object:
#interface Alarm : NSObject
#property(nonatomic, copy) NSNumber *id;
#property(nonatomic, copy) NSString *start;
#property(nonatomic, copy) NSString *end;
#property(nonatomic, copy) NSString *code;
#property(nonatomic, copy) NSString *line;
#property(nonatomic, copy) NSString *station;
#property(nonatomic, copy) NSNumber *stationLeft;
#property(nonatomic) BOOL available;
#property(nonatomic, copy) NSNumber *times;
#end
This is my code to post.
DeviceAlarm* devicealarm = [[DeviceAlarm alloc] init];
Alarm* alarm = [[Alarm alloc] init];
alarm.start = #"8:00";
alarm.end = #"9:30";
alarm.line = #"156";
alarm.code = #"fasdfasdf";
alarm.station = #"asdfas";
alarm.stationLeft = #1000;
alarm.available = true;
alarm.times = #1;
devicealarm.alarm = [NSArray arrayWithObjects:alarm , nil];
devicealarm.deviceToken = #"adsfasdfasdf";
RKObjectMapping *alarmMapping = [RKObjectMapping requestMapping];
[alarmMapping addAttributeMappingsFromArray:#[#"start",#"end",#"code",#"station", #"stationLeft",#"available",#"times",#"line"]];
RKObjectMapping *deviceMapping = [RKObjectMapping requestMapping];
RKRelationshipMapping *alarmRelationship = [RKRelationshipMapping
relationshipMappingFromKeyPath:#"alarm"
toKeyPath:#"alarm"
withMapping:alarmMapping];
[deviceMapping addAttributeMappingsFromArray:#[#"deviceToken"]];
[deviceMapping addPropertyMapping:alarmRelationship];
NSString* path = #"/api/alarm/asdfasdf";
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:deviceMapping
objectClass:[DeviceAlarm class]
rootKeyPath:nil];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[DeviceAlarm DeviceAlarmResponseMapping]
pathPattern:nil
keyPath: nil
statusCodes:[NSIndexSet indexSetWithIndex:200]];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:#"http://127.0.0.1:5000/"]];
[manager addRequestDescriptor:requestDescriptor];
[manager addResponseDescriptor:responseDescriptor];
[manager postObject:devicealarm path:path parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(#"Loading mapping result: %#", result);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(#"Operation failed with error: %#", error);
}];
Then I check the post data in services, I found restkit post an error array json.
alarm dict lost.
{
"deviceToken":"asdfasdfasdf",
"alarm": [
"8:30",
"9:30",
"156",
"xxxafsdfasdf",
"asdfa",
5,
true,
2
]
}
Please help me~ :)
LOL, I have fixed my issues, I changed the field type from "NSMutableArray" to "NSSet" in DeviceAlarm Object, and then it works. I don't know why. Hope it can help us.
I need to make two different types of POST coming from the User class.
//JSON Type A
{
"password":"12345",
"email":"test#gmail.com"
}
//JSON Type B
{
"user":{
"Password":"12345",
"Email":"sample#gmail.com"
}
}
I've tried to make two request descriptors and adding them to my object manager however I get the error
"Cannot add a request descriptor for the same object class as an
existing request descriptor."
My code
#interface User : NSObject
#property (nonatomic, retain) NSString * userID;
#property (nonatomic, retain) NSString * email;
#property (nonatomic, retain) NSString * password;
#property (nonatomic, retain) NSString * firstName;
#property (nonatomic, retain) NSString * lastName;
#end
- (void)setupUserMapping:(RKObjectManager *)objectManager {
// Setup user response mappings
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping addAttributeMappingsFromDictionary:#{
#"ID" :#"userID",
#"Email" : #"email",
#"Password" : #"password",
#"FirstName" : #"firstName",
#"LastName" : #"lastName",
}];
RKResponseDescriptor *responseDescriptorAuthenticate = [RKResponseDescriptor responseDescriptorWithMapping:userMapping
pathPattern:#"/Authenticate"
keyPath:nil
statusCodes:[NSIndexSet indexSetWithIndex:200]];
RKResponseDescriptor *responseDescriptorRegister = [RKResponseDescriptor responseDescriptorWithMapping:userMapping
pathPattern:#"/Register"
keyPath:nil
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:responseDescriptorRegister];
[objectManager addResponseDescriptor:responseDescriptorAuthenticate];
// Setup user request mappings
RKObjectMapping* userRequestMappingForRegister = [RKObjectMapping requestMapping];
[userRequestMappingForRegister addAttributeMappingsFromDictionary:#{
#"email" : #"Email",
#"password" : #"Password",
#"firstName" : #"FirstName",
#"lastName" : #"LastName",
}];
RKRequestDescriptor *requestDescriptorForRegister = [RKRequestDescriptor requestDescriptorWithMapping:userRequestMappingForRegister objectClass:[User class] rootKeyPath:#"user"];
RKObjectMapping* userRequestMappingForAuthenticate = [RKObjectMapping requestMapping];
[userRequestMappingForAuthenticate addAttributeMappingsFromDictionary:#{
#"userID" :#"ID",
#"email" : #"email",
#"password": #"password"
}];
RKRequestDescriptor *requestDescriptorForAuthenticate = [RKRequestDescriptor requestDescriptorWithMapping:userRequestMappingForAuthenticate objectClass:[User class] rootKeyPath:nil];
[objectManager addRequestDescriptor:requestDescriptorForRegister];
[objectManager addRequestDescriptor:requestDescriptorForAuthenticate];
}
Does anyone know how I can solve this problem without creating a separate class for these requests?
Any help is appreciated.
Thanks.
You can use a dynamic mapping to switch the serialization behaviors. If this is a common enough issue, we could conceivably add path matching to the request descriptor. I just have not had a ton of requests for such a feature.
There is an example of how to use the dynamic mapping with a request in the unit tests: https://github.com/RestKit/RestKit/blob/master/Tests/Logic/ObjectMapping/RKObjectParameterizationTest.m#L495-L534
For multiple request descriptors, I declared a new model class with the same data members as the earlier one, and then referenced it while adding the request descriptor instead of the earlier one as follow.
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[CMAGoogleUserDataModel class]];
Here the newly created class was "CMAGoogleUserDataModel"
Noted: I am not sure whether it is the optimised one or not, but it did solve my use case.
I'm working with the JSON below. The outer label is missing.
[{
"id":1,
"updated_at":"2012-01-13T17:13:47Z",
"created_at":"2012-01-13T17:13:47Z",
"name":"dave"},
{
"id":2,
"updated_at":"2012-01-13T17:13:55Z",
"created_at":"2012-01-13T17:13:55Z",
"name":"steve"
}]
I think RestKit expects
{***people:***
[{
"id":1,
"updated_at":"2012-01-13T17:13:47Z",
"created_at":"2012-01-13T17:13:47Z",
"name":"dave"},
{
"id":2,
"updated_at":"2012-01-13T17:13:55Z",
"created_at":"2012-01-13T17:13:55Z",
"name":"steve"
}]
}
#interface Data : NSObject {
Person *person;
NSArray *dogs;
}
#property (nonatomic ,retain) Person *person;
#property (nonatomic ,retain) NSArray *dogs;
#end
#interface Person : NSObject {
NSString *name;
NSNumber *personId;
NSDate *updatedAt;
NSDate *createdAt;
}
#property (nonatomic , retain) NSDate * createdAt;
#property (nonatomic , retain) NSDate * updatedAt;
#property (nonatomic , retain) NSNumber *personId;
#property (nonatomic , retain) NSString *name;
#end
Here is my mapping:
RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[Person class]];
[userMapping mapKeyPath:#"updated_at" toAttribute:#"updatedAt"];
[userMapping mapKeyPath:#"created_at" toAttribute:#"createdAt"];
[userMapping mapKeyPath:#"name" toAttribute:#"name"];
[userMapping mapKeyPath:#"id" toAttribute:#"personId"];
RKObjectMapping* dogMapping = [RKObjectMapping mappingForClass:[Dog class]];
[dogMapping mapKeyPath:#"created_at" toAttribute:#"createdAt"];
[dogMapping mapKeyPath:#"person_id" toAttribute:#"spersonId"];
[dogMapping mapKeyPath:#"name" toAttribute:#"name"];
[dogMapping mapKeyPath:#"updated_at" toAttribute:#"updatedAt"];
[dogMapping mapKeyPath:#"id" toAttribute:#"dogId"];
[[RKObjectManager sharedManager].mappingProvider setMapping:userMapping
forKeyPath:#"person"];
RKObjectRouter * router = [RKObjectManager sharedManager].router;
[router routeClass: [Person class] toResourcePath:#"/people/:personId"];
[router routeClass: [Person class] toResourcePath:#"/people"
forMethod:RKRequestMethodPOST];
RKObjectMapping *personSerializationMapping= [RKObjectMapping mappingForClass:
[NSDictionary class]];
[personSerializationMapping mapKeyPath:#"name" toAttribute:#"person[name]"];
[[RKObjectManager sharedManager].mappingProvider
setSerializationMapping:personSerializationMapping forClass: [Person class]];
Person* dave =[[Person alloc]init ];
dave.name = #"data";
NSLog(#"%#", [daveLiu name]);
//NSLog("name is %#", daveLiu.description );
[[RKObjectManager sharedManager] postObject:dave delegate:self];
UPDATE! I got the above code to work. It will save to the rails server, but I'm getting a keypath error still!
Processing PeopleController#create (for 127.0.0.1 at 2012-01-16 06:12:18) [POST]
Parameters: {"person"=>{"name"=>"data"}}
Person Create (0.4ms) INSERT INTO "people" ("updated_at", "created_at", "name") VALUES('2012-01-16 14:12:18', '2012-01-16 14:12:18', 'data')
Completed in 11ms (View: 1, DB: 0) | 200 OK [http://localhost/people]
W restkit.object_mapping:RKObjectMapper.m:60 Adding mapping error: Could not find an object mapping for keyPath: ''
E restkit.network:RKObjectLoader.m:178 Encountered errors during mapping: Could not find an object mapping for keyPath: ''
Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "Could not find an object mapping for keyPath: ''" UserInfo=0x4e6c4e0 {=RKObjectMapperKeyPath, NSLocalizedDescription=Could not find an object mapping for keyPath: ''}