RestKit/RestKit — pull request #1537 by percysnoodle (2013-07-30 08:35:17+00:00)
Title: Support JSON with keys in dots (in some cases)

If we catch NSInvalidArgumentException while creating the parent object chain, assume that this is because the JSON contains a key with dots. Fixes #1532.

This only works in some situations. Consider this JSON:

```
{
"data": {
"users.current.details": {
"id": 12345,
"name": "Simon"
}
},
"success": true
}
```

We can create a mapping in which we have a representation for each level like so: (see RKObjectMappingNextGenTest.m for the class definitions)

```
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestUser class]];
RKAttributeMapping *idMapping = [RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"userID"];
[userMapping addPropertyMapping:idMapping];
RKAttributeMapping *nameMapping = [RKAttributeMapping attributeMappingFromKeyPath:@"name" toKeyPath:@"name"];
[userMapping addPropertyMapping:nameMapping];

RKObjectMapping *innerMapping = [RKObjectMapping mappingForClass:[RKExampleGroupWithUser class]];
[innerMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"users.current.details" toKeyPath:@"user" withMapping:userMapping]];

RKObjectMapping *outerMapping = [RKObjectMapping mappingForClass:[RKExampleGroupWithGroup class]];
[outerMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"data" toKeyPath:@"userGroup" withMapping:innerMapping]];
```

We can't create a mapping which does it all in one go, like so:

```
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestUser class]];
RKAttributeMapping *idMapping = [RKAttributeMapping attributeMappingFromKeyPath:@"data.users.current.details.id" toKeyPath:@"userID"];
[userMapping addPropertyMapping:idMapping];
RKAttributeMapping *nameMapping = [RKAttributeMapping attributeMappingFromKeyPath:@"data.users.current.details.name" toKeyPath:@"name"];
[userMapping addPropertyMapping:nameMapping];
```

...but we couldn't before, so that isn't a regression. To support that kind of mapping, we'd need to change `-[RKMappingOperation applyAttributeMappings:]` at this line:

```
id value = (attributeMapping.sourceKeyPath == nil) ? self.sourceObject : [self.sourceObject valueForKeyPath:attributeMapping.sourceKeyPath];
```

However since there isn't any way of testing whether an object has a particular KVC key other than to get its value and catch the exception, we'd have to iterate over the possibilities and the code would get quite hairy.