Using RestKit 0.10.1, I have objects served similar to this json format:
{"objects": [
{"owner": 1,
"_id": 823,
"data": {
"diam": 5.0,
"plant_date": "10/02/2008"}
},
... ] }
on the client side, I do not need to have sub objects or relationships, so I flatten to attributes of my object:
[myMapping mapKeyPathsToAttibutes:
@"_id", @"id",
@"owner", @"owner",
@"data.diam", @"diam", //here is what I mean by flatten; notice data.diam -> diam
@"data.plant_date", @"plant_date", nil];
I have no problem reading this data, but when I want to serialize it, only the top-level attributes get sent to the server. When I serialize, here is what the server gets:
{"_id":0,"owner":1}
Note that I have correctly (I think) registered the Serialization mapping with an inverseMapping of the above:
[objectManager.mappingProvider setSerializationMapping:[myMapping inverseMapping] forClass:[MyClass class]];
When I post the object like so:
myObject = [MyClass object];
myObject.diam = [NSNumber numberWithInt:5];
myObject.plant_date = myDate;
[[RKObjectManager sharedManager] postObject:myObject delegate:self];
I would like to have the complete, unflattened structure:
{"_id":0,"owner":1, "data": {"diam": 5.0, "plant_date": "10/02/2008"} }
How can I achieve posting a keypath (i.e. “data.diam”) mapping registered object to server using RestKit?
Note that this bug has been fixed in RestKit on the development for release in 0.20. See the changeset @ https://github.com/RestKit/RestKit/commit/64e9c7cb6d04dd8750e9f663fc998bbe738945e9