RestKit not mapping recursive JSON to objects - ios

Edit 2
For reasons that I dont quite understand, adding the response descriptor directly to httpsRKManager, instead of the app layering, got RK to recognize the "Response" response descriptor. The issue now is that it seems not to recognize the attribute mapping for "ErrorStatus" /end edit
I have three issues. First Shops and the recursive object Shop do not show up as part of the LLSResult object. Second the objects are not populated from the result, and third, is there a way to skip Shops altogether. The context is I am migrating an existing app from a Ruby server to a .NET server with a different api. To compound matters. two weeks ago I had never touched a Mac. let alone any of the ecosystem.
Edit 2:
The Response Descriptor fix
NSString *path = [[ConfigManager sharedInstance] getEventsURL];
[[[AppCore sharedInstance] httpsRKManager]addResponseDescriptor:
[RKResponseDescriptor responseDescriptorWithMapping:[LLSResponse jsonMapping]
method:RKRequestMethodAny
pathPattern:path
keyPath:#"Response"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
// This didn work
//[BaseRO addResponseDescriptorForPathPattern: [[ConfigManager sharedInstance] getEventsURL]
// withMapping:[LLSResponse jsonMapping]];
The log for edit 2:
} to object with object mapping (null)
2015-12-11 10:19:24.805 The Clymb[5234:149794] D restkit.object_mapping:RKPropertyInspector.m:131 Cached property inspection for Class 'LLSResponse': {
debugDescription = {
isPrimitive = 0;
keyValueCodingClass = NSString;
name = debugDescription;
};
description = {
isPrimitive = 0;
keyValueCodingClass = NSString;
name = description;
};
events = {
isPrimitive = 0;
keyValueCodingClass = Events;
name = events;
};
hash = {
isPrimitive = 1;
keyValueCodingClass = NSNumber;
name = hash;
};
shops = {
isPrimitive = 0;
keyValueCodingClass = Shops;
name = shops;
};
status = {
isPrimitive = 0;
keyValueCodingClass = ErrorStatus;
name = status;
};
}
2015-12-11 10:19:24.805 The Clymb[5234:149797] D restkit.object_mapping:RKMappingOperation.m:592 Mapping one to one relationship value at keyPath 'ErrorStatus' to 'ErrorStatus'
2015-12-11 10:19:24.806 The Clymb[5234:149797] T restkit.object_mapping:RKMappingOperation.m:550 Performing nested object mapping using mapping ErrorStatus> for data: {
"#ID" = "";
"#Status" = OK;
}
2015-12-11 10:19:24.806 The Clymb[5234:149797] D restkit.object_mapping:RKMappingOperation.m:868 Starting mapping operation...
2015-12-11 10:19:24.807 The Clymb[5234:149797] T restkit.object_mapping:RKMappingOperation.m:869 Performing mapping operation: for 'ErrorStatus' object. Mapping values from object {
"#ID" = "";
"#Status" = OK;
} to object with object mapping (null)
end of edit 2
The JSON
{
Response: {
ErrorStatus: {
#ID: "",
#Status: "OK"
},
Events: {
Event: [
{
#Title: "Test - Hero 1",
#ID: "00010033005800000000",
#Start: "2015-12-07 09:00:00Z",
#End: "2015-12-31 08:00:00Z",
#Status: "Active",
#Image_Small: "http://www.leftlanesports.com/App_Themes/Default/graphics/Events/291_00010033005800000000.jpg",
#Image_Large: "http://www.leftlanesports.com/App_Themes/Default/graphics/Events/447_00010033005800000000.jpg",
#TypeCode: "EVTH1",
Description: {
#cdata-section: "yo"
},
ShortDescription: {
#cdata-section: "50%##Hero Event 1"
}
},
...
]
},
Shops: {
Shop: [
{
#Title: "Adventures",
#ID: "00030000000000000000"
},
{
#Title: "Apparel",
#ID: "00080000000000000000",
Shop: [
{
#Title: "Mens",
#ID: "00080001000000000000",
Shop: [
{
#Title: "Accessories",
#ID: "00080001003700000000",
Shop: [
The .h file
#import
#import "BaseRO.h"
#import "EventDO.h"
#class LLSResponse;
#class Events;
#class ErrorStatus;
#interface LLSResponse : NSObject
#property (nonatomic, strong) ErrorStatus * status;
#property (nonatomic, strong) Events * events;
- getAllEvents;
#end
#interface ErrorStatus : NSObject
#property (nonatomic, copy) NSString * _id;
#property (nonatomic, copy) NSString * Status;
#end
#interface Events : NSObject ;
#property (nonatomic, strong) NSMutableArray *events;
#end
#interface Shop : NSObject ;
#property (nonatomic, copy) NSString * _id;
#property (nonatomic, copy) NSString * title;
#property (nonatomic, strong) NSMutableArray *shops;
#end
#interface Shops : NSObject ;
#property (nonatomic, strong) NSMutableArray * shops;
#end
The relevant parts after edit 2 seem to be Response.jsonMapping and ErrorStatus.jsonMapping.
The .m file
#implementation LLSResponse
+ (RKObjectMapping *)jsonMapping
{
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); //??? debugging
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[LLSResponse class]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:#"ErrorStatus"
toKeyPath:#"ErrorStatus"
withMapping:[ErrorStatus jsonMapping]]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:#"Shops"
toKeyPath:#"Shops"
withMapping:[Shops jsonMapping]]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:#"Events"
toKeyPath:#"Events"
withMapping:[Events jsonMapping]]];
return entityMapping;
}
- (NSArray *) getAllEvents
{
Events * events = self.events;
NSArray *allEvents = events.events;
return allEvents;
}
#end
#implementation ErrorStatus
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[ErrorStatus class]];
[entityMapping addAttributeMappingsFromDictionary:#{
#"#ID" : #"_id",
#"#Status" : #"Status"
}];
return entityMapping;
}
#end
#implementation Events
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[Events class]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:#"Event"
toKeyPath:#"Event"
withMapping:[EventDO jsonMapping]]];
return entityMapping;
}
#end
#implementation Shop
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[Shop class]];
[entityMapping addAttributeMappingsFromDictionary:#{
#"#ID" : #"_id",
#"#Title" : #"title"
}];
//RKEntityMapping * shopMapping = [RKEntityMapping mappingForClass: [Shop class]];
//[entityMapping addRelationshipMappingWithSourceKeyPath:#"Shop" mapping:entityMapping];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:#"Shop"
toKeyPath:#"Shop"
withMapping:entityMapping]];
return entityMapping;
}
#end
#implementation Shops
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[Shops class]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:#"Shop"
toKeyPath:#"Shop"
withMapping:[Shop jsonMapping]]];
return entityMapping;
}
#end
When I run the app in the Xcode simulator I find that it has successfully called the server and the above JSON has been returned. The LLSResponse object, the ErrorStatus Object, and the Events object have been created. However the Shops object has not. So there is a problem in the Shops/Shop mapping, but I cant see it. When I examine the objects none of them have been populated. I dont know whether this is a separate issue or a consequence of the Shops problem.
Shops is actually extraneous data returned by the API. Is there a way to skip it? What happens if it is not mapped at all; is it an error?
EDIT 2: Text deleted.
Thanks

Related

Restkit - Relationship mapping not working

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.

RestKit Mapping a string array without key paths

I'm having a problem mapping a JSON array of strings with no key paths using RestKit 0.20.3. My classes are based on the the example in the RestKit wiki.
JSON:
"feature_list":{
"property":["test","test ","test","test"],
"street":["test1","foo","bar"],
"garden":["foo","bar"],
"other":["foo","bar", "test2"]
}
Classes:
#interface FeatureList : NSManagedObject
#property(nonatomic, strong) NSSet *property;
#property(nonatomic, strong) NSSet *street;
#property(nonatomic, strong) NSSet *garden;
#property(nonatomic, strong) NSSet *other;
#end
#interface Feature : NSManagedObject
#property(nonatomic, strong) NSString *featureType;
#end
Mapping Setup:
+ (RKMapping *)featureListMapping {
RKObjectMapping *mapping = [RKEntityMapping mappingForEntityForName:#"FeatureList" inManagedObjectStore:objectStore];
[mapping addRelationshipMappingWithSourceKeyPath:#"property" mapping:[self featureMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:#"street" mapping:[self featureMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:#"garden" mapping:[self featureMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:#"other" mapping:[self featureMapping]];
}
+ (RKMapping *)featureMapping {
RKObjectMapping *mapping = [RKEntityMapping mappingForEntityForName:#"Feature" inManagedObjectStore:objectStore];
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:#"featureType"]];
return mapping;
}
When debugging the feature.featureType object in Xcode, a RKMappingSourceObject object is returned with the value stored in an object property, which I can't access.
When printing feature.featureType.class, NSCFString is printed.
for (Feature * feature in featureList.property)
{
//feature.featureType is a RKMappingSourceObject in the debugger
NSString *featureStr = feature.featureType.class; //prints NSCFString
}
Log output:
Mapped attribute value from keyPath '(null)' to 'featureType'. Value: test ({
HTTP = {
request = {
URL = "http://localhost:3000/api/v1/test";
headers = {
};
method = GET;
};
response = {
URL = "http://localhost:3000/api/v1/test";
headers = {
"Cache-Control" = "max-age=0, private, must-revalidate";
"Content-Type" = "application/json; charset=utf-8";
Etag = "\"193d0f470155872e5b36e9f7586c0c8f\"";
"Proxy-Connection" = Close;
Server = "thin 1.5.0 codename Knife";
"X-Request-Id" = 0e4de78e656ef2165699385695cdfe75;
"X-Runtime" = "0.092788";
"X-UA-Compatible" = "IE=Edge";
};
};
};
mapping = {
collectionIndex = 1;
rootKeyPath = response;
};
})
Any suggestions would be appreciated, Thanks
Basically, you can use any method on the returned proxy object other than description. That means not supplying it as a variable to NSLog.
The true objects will be stored into the data store. Depending on what you need to do you may want to go and retrieve them directly (by fetching or using the managed object id).
I don't know about RestKit, but it seems that the 4 calls to featureMapping are each inserting a new RKAttributeMapping - that does not seem to make any sense. Maybe this is the reason you have a problem with your featureType property.

RestKit mapping to a property only

I have a JSON response as follows:
{
response : {
data : {
subjects : [
{
},
{
}
]
}
}
}
and i have a NSManagedObject as follows:
#interface Department : NSManagedObject
#property (nonatomic, retain) NSNumber * id;
#property (nonatomic, retain) NSString * name;
#property (nonatomic, retain) NSSet *subjects;
#end
I have a department record in Department table with id = 1 and name = "Physics". I want to modify this existing department with obtained subjects from response JSON data. the subjects field only to be updated rest should be kept same. Would you please tell me the RestKit 0.20 mapping code for this?
UPDATE
this is the mapping i performed:
NSDictionary *subMappingDict = #{
#"id": #"id",
#"sub_name": #"name"
};
RKEntityMapping *subMapping = [RKEntityMapping mappingForEntityForName:#"Subject" inManagedObjectStore:managedObjectStore];
[subMapping addAttributeMappingsFromDictionary:subMappingDict];
subMapping.identificationAttributes = #[#"id"];
RKEntityMapping *deptMapping = [RKEntityMapping mappingForEntityForName:#"Department" inManagedObjectStore:managedObjectStore];
[deptMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"subjects" toKeyPath:#"subjects" withMapping:subMapping]];
RKEntityMapping *collegeMapping = [RKEntityMapping mappingForEntityForName:#"College" inManagedObjectStore:managedObjectStore];
[collegeMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"data" toKeyPath:#"department" withMapping:deptMapping]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:collegeMapping pathPattern:nil keyPath:#"response" statusCodes:statusCodes];
I have an existing College record which has an existing Department record. Here i want to update Department's subjects field only by the mapping.

Parsing JSON using RestKit

I have been using RestKit for sometime but some APIs have changed in the latest version and I'm no longer able to parse simple JSON.
Here's the payload I have:
{
"result":true,
"items":[
{
"id":"1",
"receiver":"11011101"
},
{
"id":"2",
"receiver":"11011101"
}
]
}
How can I parse the contents of the "items" dictionary as instances of the object Conversation I have created?
Using the code below doesn't work (objects are never mapped):
RKObjectMapping* conversationMapping = [RKObjectMapping mappingForClass:[Conversation class]];
[conversationMapping mapKeyPath:#"id" toAttribute:#"id"];
[conversationMapping mapKeyPath:#"receiver" toAttribute:#"receiver"];
[[RKObjectManager sharedManager].mappingProvider setMapping:conversationMapping forKeyPath:#"items"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:#"/getConversations" delegate:self];
Conversation class
#interface Conversation : NSObject {
NSString *id;
NSString *receiver; }
+ (void)objectMapping;
#property (nonatomic, strong) NSString *id; #property (nonatomic, strong) NSString *receiver;
#end
#implementation Conversation
#synthesize id;
#synthesize receiver;
+ (void)objectMapping {
RKObjectMapping* conversationMapping = [RKObjectMapping mappingForClass:[Conversation class]];
[conversationMapping mapKeyPath:#"id" toAttribute:#"id"];
[conversationMapping mapKeyPath:#"receiver" toAttribute:#"receiver"];
[[RKObjectManager sharedManager].mappingProvider setMapping:conversationMapping forKeyPath:#"items"];
}
#end
How is your root object defined (the one that holds "result" and your Conversation "items")? That should look something like this:
#interface MyResponse
#property (nonatomic, strong) NSArray* items;
#property (nonatomic, assign) BOOL result;
with the appropriate mapping for that as well.
I solved the problem. It was something totally not related to RestKit. The content type of the response coming back from the server was not set to JSON, after fixing that object mapping worked fine.

Rails way to change current json output

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: ''}

Resources