So i am trying to mapping a JSON object without KVC with Restkit 0.20
The JSON whithout KVC
{
"created_at": "2013-03-11T22:13:05Z",
"facebookId": "2343434322",
"firstname": "testuser",
"id": 197,
"mail": "test@gmail.com",
"name": "test",
"phone": "098748394",
"sex": null,
"twitterId": null,
"updated_at": "2013-03-11T22:13:05Z",
"vehiculeDescription": "car",
"recommendCount": 0
}
My app delegate
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:WEBSERVICE]];
// Initialize managed object store
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"KojoClient" ofType:@"momd"]];
// NOTE: Due to an iOS 5 bug, the managed object model returned is immutable.
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
manager.managedObjectStore = managedObjectStore;
RKEntityMapping *utilisateurMapping =
[RKEntityMapping mappingForEntityForName:NSStringFromClass([Utilisateur class]) inManagedObjectStore:manager.managedObjectStore];
utilisateurMapping.identificationAttributes = @[@"remoteid"];
[utilisateurMapping addAttributeMappingsFromDictionary:@{
@"remoteid": @"id",
@"name": @"name",
@"firstname": @"firstname",
@"phone": @"phone",
@"facebookid": @"facebookId",
@"mail": @"mail",
@"vehiculeDescription" : @"vehiculeDescription",
@"recommendCount" : @"recommendCount",
@"created_at": @"created_at",
@"updated_at": @"updated_at",
@"twitterId": @"twitterId"
}];
/**
Register our mappings with the provider
*/
RKResponseDescriptor* utilisateursDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:[utilisateurMapping inverseMapping]
pathPattern:@"/utilisateurs"
keyPath:@""
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKResponseDescriptor* utilisateurDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:[utilisateurMapping inverseMapping]
pathPattern:@"/utilisateurs/:remoteid"
keyPath:@""
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKResponseDescriptor* facebookUtilisateurDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:[utilisateurMapping inverseMapping]
pathPattern:@"/face_utilisateurs/:facebookid"
keyPath:@""
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptorsFromArray:@[utilisateursDescriptor, utilisateurDescriptor, facebookUtilisateurDescriptor]];
// Serialize to JSON
manager.requestSerializationMIMEType=RKMIMETypeJSON;
/**
Complete Core Data stack initialization
*/
[managedObjectStore createPersistentStoreCoordinator];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Application.sqlite"];
NSError *error;
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil withConfiguration:nil options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error];
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);
// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];
// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
The problem is when i want to get my objet with :
[[RKObjectManager sharedManager] getObjectsAtPath:path parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
if(![[mappingResult firstObject] isKindOfClass:[Utilisateur class]]) {
//Dont work
}
} nil];
The RKMappingResult object has no class.
But the mapping work
Printing description of mappingResult->_keyPathToMappedObjects: { "" = { "created_at" = "2013-03-11T22:13:05Z"; facebookid = 4567898765; firstname = Test; mail = "test@gmail.com"; name = TestName; phone = 45678976587; recommendCount = 0; remoteid = 197; "updated_at" = "2013-03-11T22:13:05Z"; vehiculeDescription = "test"; }; }
I don't understand why my object mapped has no class.
I have follow the Object Mapping Tutorial without KVO
And can't change the server JSON style.
Update 1
I try without the NSStringFromClass, dont work.