I have a JSON response from my server. The data, taken from the RestKit log looks like this:
sourceObject: (
{
place = {
"place_id" = "3cc1e372-f9d9-11e0-aba9-9415ab1a8034";
placeinfo = {
latitude = "12.5846738815";
longtitude = "55.6815948486";
"place_id" = "3cc1e372-f9d9-11e0-aba9-9415ab1a8034";
};
timestamp = "2011-10-19 00:33:44";
};
},
{
place = {
"place_id" = "b65e36e0-f9d9-11e0-aba9-9415ab1a8034";
placeinfo = {
latitude = "12.5720376968";
longtitude = "55.6785774231";
"place_id" = "b65e36e0-f9d9-11e0-aba9-9415ab1a8034";
};
timestamp = "2011-10-19 00:37:08";
};
},
{
Timestamps = {
"latest_update" = "2011-10-18 17:12:09";
uuid = "8c6fb842-f99b-11e0-aba9-9415ab1a8034";
};
} )and targetObject: (null)
The data is mapped into 3 objects:
Place, Placeinfo and LatestDBUpdate.
The problem is:
In the above JSON response there are 2 place objects and 2 nested PlaceInfo objects,connected with a One To Many relationship.
There is also a LatestDBUpdate object that relates to the Timestamps keyword.
Restkit will map 3 Place objects, and one will be all NULL. The 2 other Place objects are mapped correctly and relations are also correct. It should of course only map 2 Place objects!
The LatestDBUpdate mapping s also mapping the Timestamps correct.
I have determined, that if i remove the Timestamps part of the JSON respons, then the mapping is correct, with only 2 place objects.
But i need the Timestamps part to be there! I have no idea how to fix this! any ideas - I could really use some input, since i have used hours upon hours on this!
Here are the mapping setup used:
//Place mapping
if (!self.placeManagedObject){
self.placeManagedObject = [RKManagedObjectMapping mappingForClass:[Place class]];
self.placeManagedObject.primaryKeyAttribute = @"UUID";
self.placeManagedObject.setDefaultValueForMissingAttributes = YES;
[self.placeManagedObject mapKeyPath:@"place_id" toAttribute:@"UUID"];
[self.placeManagedObject mapKeyPath:@"timestamp" toAttribute:@"timestamp"];
}
//PlaceInformation mapping
if (!self.placeInfoManagedObject){
self.placeInfoManagedObject = [RKManagedObjectMapping mappingForClass:[PlaceInfo class]];
self.placeInfoManagedObject.primaryKeyAttribute = @"UUID";self.placeInfoManagedObject.setDefaultValueForMissingAttributes = YES;
[placeInfoManagedObject mapKeyPath:@"place_id" toAttribute:@"UUID"];
[placeInfoManagedObject mapKeyPath:@"longtitude" toAttribute:@"longtitude"];
[placeInfoManagedObject mapKeyPath:@"latitude" toAttribute:@"latitude"];
}
//latestDBUpdate timestamp mapping
if (!self.latestDBUpdateManagedObject){
self.latestDBUpdateManagedObject = [RKManagedObjectMapping mappingForClass:[LatestDBUpdate class]];
self.latestDBUpdateManagedObject.primaryKeyAttribute = @"latest_update";
[self.latestDBUpdateManagedObject mapKeyPath:@"latest_update"toAttribute:@"latest_update"];
[self.latestDBUpdateManagedObject mapKeyPath:@"uuid" toAttribute:@"uuid"];
}
//Set mapping relations
[self.placeManagedObject mapRelationship:@"placeinfo" withMapping:self.placeInfoManagedObject];
// Register mapping with the provider -
[self.objectManager.mappingProvider setMapping:self.placeManagedObject forKeyPath:@"place"];
[self.objectManager.mappingProvider setMapping:self.placeInfoManagedObject forKeyPath:@"placeinfo"];
[self.objectManager.mappingProvider setMapping:self.latestDBUpdateManagedObject forKeyPath:@"Timestamps"];