restkit-0.20

RestKit RKMappingTest JSON array

淺唱寂寞╮ 提交于 2019-12-02 04:37:37
I'm using RestKit ~> 0.20.3 and RestKit/Testing ~> 0.20.3. So this is an example of my mapping: RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[PlayerVO class]]; [mapping addAttributeMappingsFromArray:@[@"firstName", @"middeName", @"lastName", @"dob", @"sex"]]; This is my mock data: NSDictionary *data = @{@"players": @[@{@"firstName": @"Ahmed", @"middleName": @"Ahmed", @"lastName": @"Ahmed", @"dob": @"100", @"sex": @"m"}]}; This is my mappingTest : RKMappingTest *mappingTest = [RKMappingTest testForMapping:mapping sourceObject:data destinationObject:nil]; And finally my

Feeding parsed data to RKMapperOperation throws NSUnknownKeyException

a 夏天 提交于 2019-12-02 01:23:45
See my other question for background: Will RestKit's dynamic mapping solve this complex JSON mapping? Due to the way the server structures the json data that I need to convert into NSManagedObject s, I'm passing the parsed json to do a direct object mapping, like so: RKObjectMapping *mapping = [RKObjectMapping requestMapping]; [mapping addAttributeMappingsFromDictionary:@{@"id": @"id", @"name": @"name"}]; NSDictionary *mappingsDictionary = @{ [NSNull null]: mapping }; RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithRepresentation:dataArray mappingsDictionary:mappingsDictionary];

RestKit 0.20.1 How to map parent id

折月煮酒 提交于 2019-12-01 13:03:45
Given this XML payload: <payload> <year yearNum="2013"> <month monthNum="6" desc="This month was an enlightening month"/> <month monthNum="5" desc="This month was a questioning month"/> <month monthNum="4" desc="This month was a good month"/> <month monthNum="3" desc="This month was a crazy month"/> <month monthNum="2" desc="This month was a dry month"/> <month monthNum="1" desc="This month was a slow month"/> </year> <year yearNum="2012"> <month monthNum="12" desc="This month was a cold month"/> <month monthNum="11" desc="This month was an expensive month"/> <month monthNum="10" desc="This

RestKit: mapping JSON array of strings

独自空忆成欢 提交于 2019-11-30 07:36:22
Given the following JSON: { "someKey":"someValue", "otherKey":"otherValue", "features":[ "feature1", "feature2", "feature3" ] } I am mapping this JSON into NSManagedObject s with RKMapperOperation and RKEntityMapping (in this example I would have 2 entity mappings: one for the top level object and another one for my Feature class). The top level object mapping is trivial: two attribute mappings plus a relationship one(features) for the relation with Feature. My question is,how to map the features JSON array into an array of Feature objects? The Feature class has just one property name where I

About the object sequence in the RestKit

孤人 提交于 2019-11-29 15:57:33
I recently used RestKit to handle my net request affairs. There is a solution for the sort with the sort descriptor. But there is no sort key for the data sent by the server. How can I keep the data in the same sequence as the server. There is a solution that I can add a sortID in the object, but this is not very elegant. I want to know if there is any api in RestKit for this problem? You should add sortID to the object - this is the appropriate solution. To populate it with a value you need to use the @metadata made available to your mappings: @"@metadata.mapping.collectionIndex" : @"sortID"

RestKit: How to handle empty response.body?

吃可爱长大的小学妹 提交于 2019-11-29 15:10:44
I request something with POST, and the server just sends status-code 200 with a content-length of 0 back. How can I handle this? I'm not allowed to add a RKResponseDescriptor without mapping, nor not add the RKResponseDescriptor. Ah, I just found out, you can create a mapping for the NSNull class. That seems to work. Here's the code: { RKObjectMapping* responseMapping = [RKObjectMapping mappingForClass:[NSNull class]]; RKResponseDescriptor* response = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping method:RKRequestMethodAny pathPattern:@"entry/sync" keyPath:nil statusCodes

Restkit 0.20 JSON Mapping along with additional offline data

五迷三道 提交于 2019-11-28 12:49:57
So let's say I have a JSON object like such: { "userList" : [ { "ID" : 1, "firstName" : "John", "lastName" : "Doe" }, { "ID" : 2, "firstName" : "Jane", "lastName" : "Doe" } ] } I am able to map this object into my user class which have the following attribute: ID, firstName, lastName, createdDate, modifiedData The Problem arise when I am need to update modified date I want to be able to insert a data-time stamp whenever I do a mapping along with when I modified the data while in offline mode. So my question is, how do I map JSON object to Core Data while also inserting some data that is not

About the object sequence in the RestKit

喜欢而已 提交于 2019-11-28 10:39:20
问题 I recently used RestKit to handle my net request affairs. There is a solution for the sort with the sort descriptor. But there is no sort key for the data sent by the server. How can I keep the data in the same sequence as the server. There is a solution that I can add a sortID in the object, but this is not very elegant. I want to know if there is any api in RestKit for this problem? 回答1: You should add sortID to the object - this is the appropriate solution. To populate it with a value you

RestKit: How to handle empty response.body?

。_饼干妹妹 提交于 2019-11-28 09:11:59
问题 I request something with POST, and the server just sends status-code 200 with a content-length of 0 back. How can I handle this? I'm not allowed to add a RKResponseDescriptor without mapping, nor not add the RKResponseDescriptor. 回答1: Ah, I just found out, you can create a mapping for the NSNull class. That seems to work. Here's the code: { RKObjectMapping* responseMapping = [RKObjectMapping mappingForClass:[NSNull class]]; RKResponseDescriptor* response = [RKResponseDescriptor

RestKit 2.0 : Mapping - second entitiy nil when not unique

末鹿安然 提交于 2019-11-28 02:25:38
I am trying to map an array of 'Comments' to a Comment entity that has a sub-entity 'testUser', the person who wrote the comment. Everything is mapping fine as long as the testUsers for all comments are unique. If a user writes two comments, the second comment will have a nil testUser object. RestKit is mapping the second comment's testUser to the same object as the first testUser, even they belong to two seperate comment-objects. You can see this in the mapping results below. How can I avoid this happening? Many many thanks. Al // Test one mapping result Mapped relationship object from