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.
Related
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
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]]];
I am using RestKit for mapping data from my api to CoreData entities and i wonder how can i get additional data from response. For example my api return structure like:
{
"items": [
{
"id": 1,
"title": "Title"
},
{
"id": 2,
"title": "Title 2"
}
],
"someParameter": "someValue"
}
i already have right mappings for shared object manager so i just send request:
[[RKObjectManager sharedManager] getObjectsAtPath:#"_api/items"
parameters:parameters
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
//handle success
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
//handle error
}];
How can i get someParameter value in success block? Is this possible?
You will need to tweak your mapping slightly. If you changed it as follows you should be able to get RESTkit to parse the 'someParameter' attribute for you. You need to have two classes (Parent and Child).
The Parent class has 2 attributes (someParameter and an array of Child objects). The addRelationshipMappingWithSourceKeyPath is what ties the Parent and Child object mappings together.
Code:
RKObjectMapping *parentMapping = [RKObjectMapping mappingForClass:[Parent class]];
[beaconActionMapping addAttributeMappingsFromDictionary:#{
#"someParameter" : #"someParameter"
}];
RKObjectMapping *childMapping = [RKObjectMapping mappingForClass:[Child class]];
[beaconMapping addAttributeMappingsFromDictionary:#{
#"id" : #"childId",
#"title" : #"title"
}];
[parentMapping addRelationshipMappingWithSourceKeyPath:#"items" mapping:childMapping];
Class hierarchy:
#interface Parent : NSObject
#property(nonatomic,strong) NSString *someParameter;
#property(nonatomic,strong) NSArray *items; // Array of Child objects
#end
#interface Child : NSObject
#property(nonatomic,strong) NSString *childId;
#property(nonatomic,strong) NSString *title
#end
You can add an additional response descriptor with a key path of someParameter. You can use that with a nil key path mapping to extract the string value into an object of your choice (usually a custom class).
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 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.