0
votes

I have a JSON payload that is being returned from my server and is structured like this:

{"users":[users]}

Using a simple RKObjectMapping and RKResponseDescriptor, I'm able to successfully map this JSON into a collection of User objects when I use getObjectsAtPath, but now I'd like to make a slight modification to the JSON server-side. Namely, I'd like to add a key-path

{"users":[users], "more":true}

where the key-path "more" indicates whether there are more users to load that are not included in the "users" array. The problem I'm having is that I can't find a simple way to access the value of this "more" key-path. Ideally, I'd like to define a Mapping and Response Descriptor that map "more" into a BOOL (or NSNumber), but I'm having trouble figuring out how to do this. Adding a mapping like

RKObjectMapping *moreMapping = [RKObjectMapping mappingForClass:[NSNumber class]]

with ResponseDescriptor

[RKResponseDescriptor responseDescriptorWithMapping:moreMapping pathPattern:pathPattern
keyPath:@"more" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

Doesn't do the trick. Ultimately, in the success block of getObjects, I'd like my RKMappingResult to be structured like so:

@{@"users":[users], @"more":1}

Any tips?

1

1 Answers

0
votes

RestKit is based around mapping data into objects, not to objects in the way you're after. The closest you can get is to map the true into an NSNumber inside a dictionary or array. Try:

RKObjectMapping *moreMapping = [RKObjectMapping requestMapping];
[moreMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"more"]];