mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-12 17:43:34 +08:00
Remove the ignoreUnknownKeyPaths option. closes #840
This commit is contained in:
@@ -373,27 +373,11 @@ id RKTransformValueFromClassToClass(id value, Class sourceType, Class destinatio
|
||||
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 @@ id RKTransformValueFromClassToClass(id value, Class sourceType, Class destinatio
|
||||
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];
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@ static NSString *RKDestinationKeyPathFromTransformationBlockWithSourceKeyPath(RK
|
||||
self.setNilForMissingRelationships = NO;
|
||||
self.forceCollectionMapping = NO;
|
||||
self.performKeyValueValidation = YES;
|
||||
self.ignoreUnknownKeyPaths = NO;
|
||||
self.sourceToDestinationKeyTransformationBlock = defaultSourceToDestinationKeyTransformationBlock;
|
||||
}
|
||||
|
||||
|
||||
@@ -388,87 +388,6 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user