My question is very similar to RestKit: mapping JSON array of strings, except it is specific to RestKit 0.09. I have looked at several other questions but am still stuck.
For reasons beyond my control I cannot upgrade to RestKit 0.20. The JSON I'm working with is:
{
"brands":[
"AN",
"UO",
"FP",
"TR",
"BN"
],
"meta":{
"message":"Current Registry Configuration."
},
"event_types":[
"WEDDING",
"ANNIVERSARY",
"BIRTHDAY",
"HOUSEWARMING",
"SPECIAL OCCASION"
],
"links":[
]
}
I am able to map the "meta" (and several other domain) objects just fine. But I have not been able to map "event_types", and have no need for "brands" or "links".
My current code is as follows:
+ (void) addElementMappings:(RKObjectMapping *)mapping
{
if ([[self superclass] respondsToSelector:@selector(addElementMappings:)]) {
[[self superclass] performSelector:@selector(addElementMappings:)
withObject:mapping];
}
[mapping mapKeyPath:@"event_types"
toAttribute:@"eventType"];
RKObjectManager* objectManager = [RKObjectManager sharedManager];
if (![objectManager.mappingProvider mappingForKeyPath:@"event_types"]) {
[objectManager.mappingProvider setMapping:mapping
forKeyPath:@"event_types"]; // for KVC path
}
}
and eventType is a NSArray (I've also tried defining it as NSString - same results as below).
As is, the code throws an exception "this class is not key value coding-compliant for the key event_types."
If I change the mapKeyPath from @"event_types" to nil (similar to 0.20), I get an exception "Cannot define an element mapping an element name to map from".
If I omit the [mapping mapKeyPath:toAttribute] entirely, there are no exceptions but of course I only get the meta object, not event_types.
In RestKit 0.09, how do I map attributes without keys?