Skip to content

Commit

Permalink
Remove the ignoreUnknownKeyPaths option. closes RestKit#840
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed Nov 20, 2012
1 parent 36c6060 commit 7888a55
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 124 deletions.
38 changes: 5 additions & 33 deletions Code/ObjectMapping/RKMappingOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -373,27 +373,11 @@ - (BOOL)applyAttributeMappings:(NSArray *)attributeMappings
continue;
}

if (self.objectMapping.ignoreUnknownKeyPaths && ![self.sourceObject respondsToSelector:NSSelectorFromString(attributeMapping.sourceKeyPath)]) {
RKLogDebug(@"Source object is not key-value coding compliant for the keyPath '%@', skipping...", attributeMapping.sourceKeyPath);
continue;
}

id value = nil;
@try {
if ([attributeMapping.sourceKeyPath isEqualToString:@""]) {
value = self.sourceObject;
} else {
value = [self.sourceObject valueForKeyPath:attributeMapping.sourceKeyPath];
}
}
@catch (NSException *exception) {
if ([[exception name] isEqualToString:NSUndefinedKeyException] && self.objectMapping.ignoreUnknownKeyPaths) {
RKLogWarning(@"Encountered an undefined attribute mapping for keyPath '%@' that generated NSUndefinedKeyException exception. Skipping due to objectMapping.ignoreUnknownKeyPaths = YES",
attributeMapping.sourceKeyPath);
continue;
}

@throw;
if ([attributeMapping.sourceKeyPath isEqualToString:@""]) {
value = self.sourceObject;
} else {
value = [self.sourceObject valueForKeyPath:attributeMapping.sourceKeyPath];
}

if (value) {
Expand Down Expand Up @@ -540,19 +524,7 @@ - (BOOL)applyRelationshipMappings
for (RKRelationshipMapping *relationshipMapping in [self relationshipMappings]) {
if ([self isCancelled]) return NO;

id value = nil;
@try {
value = [self.sourceObject valueForKeyPath:relationshipMapping.sourceKeyPath];
}
@catch (NSException *exception) {
if ([[exception name] isEqualToString:NSUndefinedKeyException] && self.objectMapping.ignoreUnknownKeyPaths) {
RKLogWarning(@"Encountered an undefined relationship mapping for keyPath '%@' that generated NSUndefinedKeyException exception. Skipping due to objectMapping.ignoreUnknownKeyPaths = YES",
relationshipMapping.sourceKeyPath);
continue;
}

@throw;
}
id value = [self.sourceObject valueForKeyPath:relationshipMapping.sourceKeyPath];

// Track that we applied this mapping
[mappingsApplied addObject:relationshipMapping];
Expand Down
9 changes: 0 additions & 9 deletions Code/ObjectMapping/RKObjectMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,6 @@
*/
@property (nonatomic, assign) BOOL performKeyValueValidation;

/**
When `YES`, the mapping operation will check that the object being mapped is key-value coding compliant for the mapped key. If it is not, the attribute/relationship mapping will be ignored and mapping will continue. When `NO`, property mappings for unknown key paths will trigger `NSUnknownKeyException` exceptions for the unknown keyPath.
Defaults to `NO` to help the developer catch incorrect mapping configurations during development.
**Default**: `NO`
*/
@property (nonatomic, assign) BOOL ignoreUnknownKeyPaths;

/**
Returns the default value to be assigned to the specified attribute when it is missing from a mappable payload.
Expand Down
1 change: 0 additions & 1 deletion Code/ObjectMapping/RKObjectMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ - (id)initWithClass:(Class)objectClass
self.setNilForMissingRelationships = NO;
self.forceCollectionMapping = NO;
self.performKeyValueValidation = YES;
self.ignoreUnknownKeyPaths = NO;
self.sourceToDestinationKeyTransformationBlock = defaultSourceToDestinationKeyTransformationBlock;
}

Expand Down
81 changes: 0 additions & 81 deletions Tests/Logic/ObjectMapping/RKMappingOperationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -388,87 +388,6 @@ - (void)testShouldMapADateToAStringUsingThePreferredDateFormatter
assertThat(newObject.boolString, is(equalTo(@"11-27-1982")));
}

- (void)testShouldGenerateAnUnknownKeyPathExceptionWhenIgnoreUnknownKeyPathsIsNO
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping addAttributeMappingsFromArray:@[@"invalid", @"boolString"]];
mapping.ignoreUnknownKeyPaths = NO;
TestMappable *object = [[TestMappable alloc] init];
object.boolString = @"test";
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:object destinationObject:dictionary mapping:mapping];
RKObjectMappingOperationDataSource *dataSource = [RKObjectMappingOperationDataSource new];
operation.dataSource = dataSource;
NSError *error = nil;
BOOL success;
NSException *exception = nil;
@try {
success = [operation performMapping:&error];
}
@catch (NSException *e) {
exception = e;
}
@finally {
assertThat(exception, isNot(nilValue()));
operation = nil;
}
}

- (void)testShouldOptionallyIgnoreUnknownKeyPathAttributes
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping addAttributeMappingsFromArray:@[@"invalid", @"boolString"]];
mapping.ignoreUnknownKeyPaths = YES;
TestMappable *object = [[TestMappable alloc] init];
object.boolString = @"test";
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:object destinationObject:dictionary mapping:mapping];
RKObjectMappingOperationDataSource *dataSource = [RKObjectMappingOperationDataSource new];
operation.dataSource = dataSource;
NSError *error = nil;
BOOL success;
NSException *exception = nil;
@try {
success = [operation performMapping:&error];
}
@catch (NSException *e) {
exception = e;
}
@finally {
assertThat(exception, is(nilValue()));
assertThatBool(success, is(equalToBool(YES)));
operation = nil;
}
}

- (void)testShouldOptionallyIgnoreUnknownKeyPathRelationships
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping addAttributeMappingsFromArray:@[@"boolString"]];
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"invalid" toKeyPath:@"invalid" withMapping:[RKObjectMapping mappingForClass:[TestMappable class]]]];
mapping.ignoreUnknownKeyPaths = YES;
TestMappable *object = [[TestMappable alloc] init];
object.boolString = @"test";
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:object destinationObject:dictionary mapping:mapping];
RKObjectMappingOperationDataSource *dataSource = [RKObjectMappingOperationDataSource new];
operation.dataSource = dataSource;
NSError *error = nil;
BOOL success;
NSException *exception = nil;
@try {
success = [operation performMapping:&error];
}
@catch (NSException *e) {
exception = e;
}
@finally {
assertThat(exception, is(nilValue()));
assertThatBool(success, is(equalToBool(YES)));
operation = nil;
}
}

- (void)testShouldLogADebugMessageIfTheRelationshipMappingTargetsAnArrayOfArrays
{
// Create a dictionary with a dictionary containing an array
Expand Down

0 comments on commit 7888a55

Please sign in to comment.