Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "205FD3B0153F02AA00693E13"
BuildableName = "KeyValueObjectMappingTests.octest"
BlueprintName = "KeyValueObjectMappingTests"
ReferencedContainer = "container:KeyValueObjectMapping.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
9 changes: 8 additions & 1 deletion KeyValueObjectMapping/DCGenericConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "DCNSSetConverter.h"
#import "DCCustomParser.h"
#import "DCKeyValueObjectMapping.h"
#import "DCArrayMapping.h"

@interface DCGenericConverter()
@property(nonatomic, strong) DCParserConfiguration *configuration;
Expand Down Expand Up @@ -46,7 +47,13 @@ - (id)transformValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribu
if (parsedValue) {
return parsedValue;
}


//handle "implicit" arrays, a single instance of the element type represented as a dictionary
DCArrayMapping *mapper = [self.configuration arrayMapperForMapper:attribute.objectMapping];
if (mapper) {
DCKeyValueObjectMapping *parser = [DCKeyValueObjectMapping mapperForClass:mapper.classForElementsOnArray andConfiguration:self.configuration];
return [parser parseArray:[NSArray arrayWithObject:value] forParentObject:parentObject];
}
DCKeyValueObjectMapping *parser = [DCKeyValueObjectMapping mapperForClass:attribute.objectMapping.classReference
andConfiguration:self.configuration];
value = [parser parseDictionary:(NSDictionary *) value forParentObject:parentObject];
Expand Down
20 changes: 20 additions & 0 deletions KeyValueObjectMappingTests/DCArrayOfTweetsOnUserTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ - (void) testShouldCreateAnUserWithTweets {
STAssertEquals((int)user.tweets.count, 2, @"Should have 2 tweets on array of tweets");
}

- (void) testShouldCreateAnUserWithOneImplicitTweet {

DCArrayMapping *mapper = [DCArrayMapping mapperForClassElements:[Tweet class]
forAttribute:@"tweets"
onClass:[User class]];

DCParserConfiguration *configuration = [DCParserConfiguration configuration];
[configuration addArrayMapper:mapper];

DCKeyValueObjectMapping *parser = [DCKeyValueObjectMapping mapperForClass:[User class]
andConfiguration:configuration];

NSArray *tweetArray = [jsonParsed valueForKey:@"tweets"];
Tweet *tweet = [tweetArray objectAtIndex:0];
[jsonParsed setValue:tweet forKey:@"tweets"];
User *user = [parser parseDictionary:jsonParsed];
STAssertNotNil(user.tweets, @"Tweets should not be nil");
STAssertEquals((int)user.tweets.count, 1, @"Should have 1 tweet on array of tweets");
}

- (void) testShouldCreateUserWithNilOnTweetsArray{
DCObjectMapping *objectMapping = [DCObjectMapping mapKeyPath:@"tweets_nullable"
toAttribute:@"tweets"
Expand Down