From 4bd12ea987de4e69bea93f6e5d67b561fc388aed Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Wed, 18 Jan 2012 08:45:34 -0500 Subject: [PATCH] Apply rootKeyPath within the mapper rather than the object loader --- Code/ObjectMapping/RKObjectLoader.m | 5 ++--- Code/ObjectMapping/RKObjectMapper.m | 4 +++- Specs/ObjectMapping/RKObjectMappingNextGenSpec.m | 1 + Specs/ObjectMapping/RKObjectMappingProviderSpec.m | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Code/ObjectMapping/RKObjectLoader.m b/Code/ObjectMapping/RKObjectLoader.m index 30f7628d..4154e5af 100644 --- a/Code/ObjectMapping/RKObjectLoader.m +++ b/Code/ObjectMapping/RKObjectLoader.m @@ -214,10 +214,9 @@ RKObjectMappingProvider* mappingProvider; RKObjectMapping *configuredObjectMapping = [self configuredObjectMapping]; - if (configuredObjectMapping) { - NSString* rootKeyPath = configuredObjectMapping.rootKeyPath ? configuredObjectMapping.rootKeyPath : @""; - RKLogDebug(@"Found directly configured object mapping, creating temporary mapping provider for keyPath %@", rootKeyPath); + if (configuredObjectMapping) { mappingProvider = [RKObjectMappingProvider mappingProvider]; + NSString *rootKeyPath = configuredObjectMapping.rootKeyPath ? configuredObjectMapping.rootKeyPath : @""; [mappingProvider setMapping:configuredObjectMapping forKeyPath:rootKeyPath]; } else { RKLogDebug(@"No object mapping provider, using mapping provider from parent object manager to perform KVC mapping"); diff --git a/Code/ObjectMapping/RKObjectMapper.m b/Code/ObjectMapping/RKObjectMapper.m index e1af6e33..13a7215c 100644 --- a/Code/ObjectMapping/RKObjectMapper.m +++ b/Code/ObjectMapping/RKObjectMapper.m @@ -334,7 +334,9 @@ } else if ([mappingsForContext conformsToProtocol:@protocol(RKObjectMappingDefinition)]) { id mappableData = self.sourceObject; if ([mappingsForContext respondsToSelector:@selector(rootKeyPath)] && [mappingsForContext rootKeyPath] != nil) { - mappableData = [self.sourceObject valueForKeyPath:[mappingsForContext rootKeyPath]]; + NSString* rootKeyPath = [mappingsForContext rootKeyPath]; + mappableData = [self.sourceObject valueForKeyPath:rootKeyPath]; + RKLogDebug(@"Selected object mapping has rootKeyPath. Apply valueForKeyPath to mappable data: %@", rootKeyPath); } if (mappableData) { diff --git a/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m b/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m index 08bd36d2..f858f7c6 100644 --- a/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m +++ b/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m @@ -30,6 +30,7 @@ #import "RKObjectMapper_Private.h" #import "RKObjectMapperError.h" #import "RKDynamicMappingModels.h" +#import "RKObjectMappingProvider+Contexts.h" // Managed Object Serialization Specific #import "RKHuman.h" diff --git a/Specs/ObjectMapping/RKObjectMappingProviderSpec.m b/Specs/ObjectMapping/RKObjectMappingProviderSpec.m index 3f9f2ca4..cd0161bd 100644 --- a/Specs/ObjectMapping/RKObjectMappingProviderSpec.m +++ b/Specs/ObjectMapping/RKObjectMappingProviderSpec.m @@ -23,6 +23,7 @@ #import "RKManagedObjectStore.h" #import "RKSpecResponseLoader.h" #import "RKManagedObjectMapping.h" +#import "RKObjectMappingProvider+Contexts.h" #import "RKObjectMappingProvider.h" #import "RKHuman.h" #import "RKCat.h"