diff --git a/Code/ObjectMapping/RKMappingOperation.m b/Code/ObjectMapping/RKMappingOperation.m index 7d20bc19c6..8e5b4a9cbc 100644 --- a/Code/ObjectMapping/RKMappingOperation.m +++ b/Code/ObjectMapping/RKMappingOperation.m @@ -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) { @@ -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]; diff --git a/Code/ObjectMapping/RKObjectMapping.h b/Code/ObjectMapping/RKObjectMapping.h index f4de77620b..eb2fc41f8e 100644 --- a/Code/ObjectMapping/RKObjectMapping.h +++ b/Code/ObjectMapping/RKObjectMapping.h @@ -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. diff --git a/Code/ObjectMapping/RKObjectMapping.m b/Code/ObjectMapping/RKObjectMapping.m index 39d0c11401..8296dc8e4a 100644 --- a/Code/ObjectMapping/RKObjectMapping.m +++ b/Code/ObjectMapping/RKObjectMapping.m @@ -83,7 +83,6 @@ - (id)initWithClass:(Class)objectClass self.setNilForMissingRelationships = NO; self.forceCollectionMapping = NO; self.performKeyValueValidation = YES; - self.ignoreUnknownKeyPaths = NO; self.sourceToDestinationKeyTransformationBlock = defaultSourceToDestinationKeyTransformationBlock; } diff --git a/Tests/Logic/ObjectMapping/RKMappingOperationTest.m b/Tests/Logic/ObjectMapping/RKMappingOperationTest.m index b059e9941f..c8a4dac13f 100644 --- a/Tests/Logic/ObjectMapping/RKMappingOperationTest.m +++ b/Tests/Logic/ObjectMapping/RKMappingOperationTest.m @@ -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