2
votes

I am having NSString parameters in my object getting set to NSNull when null is returned in the JSON. I would like the the NSString to be set to nil. Any Ideas?

I have tried setting [mapping setAssignsDefaultValueForMissingAttributes:NO]; but that does not seem to work even when I implement changes from Fix 1714. I'm really just spinning my wheels at this point.

Here is everything I have for making this call so far.

Returned JSON

{
    val1 = "something";
    val2 = "<null>";
}

Class cMyClass

@interface cMyClass : NSObject {
    NSString *val1;
    NSString *val2;
}

RKObjectMapping

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[cMyClass class]];
[mapping addAttributeMappingsFromDictionary:@{@"val1":@"val1", @"val2":@"val2"}];

RKResponseDescriptor

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:@"GetMyClass" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

RKObjectManager

NSURL *baseURL = [NSURL URLWithString:@"http://www.domain.com/MyAPI.svc/rest"];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];
[objectManager addResponseDescriptor:responseDescriptor];

objectManager.requestSerializationMIMEType = RKMIMETypeJSON;

[objectManager.HTTPClient setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
[objectManager.HTTPClient setParameterEncoding:AFJSONParameterEncoding];

API Call

NSDictionary *params = ...

objectManager getObjectsAtPath:@"GetMyClass" parameters:params success:(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    completionBlock:(mappingResult.array[0]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    failureBlock(error);
}];
1
How have you implemented the bug fix changes? - Wain
Yes. The getObjectsAtPath call doesn't even seem to be hitting that part of the code though. - egarlock
Did you checkout the version with the bug fix? Or you tried to copy it? Does a similar change actually need to be made somewhere else in the code? - Wain
When you look at a pull request you can see every file that the person has made changes to and what changes were made. There were just changes in this file and then some in a Test class for testing coverage. - egarlock
Ok, but people make mistakes, so have you compared your change, run the tests if you manually changed instead of checking out, checked if the same change should have been made elsewhere? - I don't know the answer to your question, but the first question should be able whether the solution you have found is correct for your situation - Wain

1 Answers

1
votes

I'm grasping at straws since I am just starting out with Restkit myself...but, do you perhaps think there might be an issue with the mappings?

It looks like the values in your cMyClass are ivars instead of properties. If I am not mistaken, unless otherwise stated, those are "protected" so you can't really access those if you are calling an instance of the class. Maybe move them to properties and see if it works from there!