Skip to content

Commit

Permalink
- Fixed nested array causing crash
Browse files Browse the repository at this point in the history
  • Loading branch information
jamztang committed Nov 9, 2011
1 parent 263607c commit e0427df
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 6 deletions.
6 changes: 6 additions & 0 deletions JTObjectMapping.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1A23E1D71469B35D002BBB85 /* JPNestedArrayTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A23E1D61469B35C002BBB85 /* JPNestedArrayTest.m */; };
1A5F56C914168CC3007145BC /* JTDateMappings.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A5F56C814168CC3007145BC /* JTDateMappings.m */; };
1A7E71C61415F96700AE157A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7E71C51415F96700AE157A /* UIKit.framework */; };
1A7E71C81415F96700AE157A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7E71C71415F96700AE157A /* Foundation.framework */; };
Expand Down Expand Up @@ -42,6 +43,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1A23E1D51469B35C002BBB85 /* JPNestedArrayTest.h */ = {isa = PBXFileReference; fileEncoding = 4; path = JPNestedArrayTest.h; sourceTree = "<group>"; };
1A23E1D61469B35C002BBB85 /* JPNestedArrayTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JPNestedArrayTest.m; sourceTree = "<group>"; };
1A5F56C714168CC3007145BC /* JTDateMappings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JTDateMappings.h; sourceTree = "<group>"; };
1A5F56C814168CC3007145BC /* JTDateMappings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JTDateMappings.m; sourceTree = "<group>"; };
1A7E71C11415F96700AE157A /* JTObjectMapping.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JTObjectMapping.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -169,6 +172,8 @@
1A7E720D141613C800AE157A /* JTUserTest.m */,
1A7E7206141602C900AE157A /* JTSocialNetworkTest.h */,
1A7E7207141602C900AE157A /* JTSocialNetworkTest.m */,
1A23E1D51469B35C002BBB85 /* JPNestedArrayTest.h */,
1A23E1D61469B35C002BBB85 /* JPNestedArrayTest.m */,
);
path = JTObjectMappingTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -308,6 +313,7 @@
1A7E720B141605B300AE157A /* JTMappings.m in Sources */,
1A7E720E141613C900AE157A /* JTUserTest.m in Sources */,
1A5F56C914168CC3007145BC /* JTDateMappings.m in Sources */,
1A23E1D71469B35D002BBB85 /* JPNestedArrayTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion JTObjectMapping/JTObjectMapping-Info.plist
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.4</string>
<string>1.0.5</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
Expand Down
2 changes: 1 addition & 1 deletion JTObjectMapping/Source/NSObject+JTObjectMapping.m
Expand Up @@ -48,7 +48,7 @@ - (void)setValueFromDictionary:(NSDictionary *)dict mapping:(NSDictionary *)mapp
} else if ([(NSObject *)obj isKindOfClass:[NSArray class]]) {
if ([mapsToValue conformsToProtocol:@protocol(JTMappings)]) {
id <JTMappings> mappings = (id <JTMappings>)mapsToValue;
NSObject *object = [[self class] objectFromJSONObject:obj mapping:mappings.mapping];
NSObject *object = [mappings.targetClass objectFromJSONObject:obj mapping:mappings.mapping];
[self setValue:object forKey:mappings.key];
} else {
NSMutableArray *array = [NSMutableArray array];
Expand Down
15 changes: 15 additions & 0 deletions JTObjectMappingTests/JPNestedArrayTest.h
@@ -0,0 +1,15 @@
//
// JPAPIsTest.h
// JTObjectMapping
//
// Created by James Apple Tang on 09/11/2011.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface JPNestedArrayTest : NSObject

@property (nonatomic, retain) NSArray *array;

@end
13 changes: 13 additions & 0 deletions JTObjectMappingTests/JPNestedArrayTest.m
@@ -0,0 +1,13 @@
//
// JPAPIsTest.m
// JTObjectMapping
//
// Created by James Apple Tang on 09/11/2011.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "JPNestedArrayTest.h"

@implementation JPNestedArrayTest
@synthesize array;
@end
30 changes: 30 additions & 0 deletions JTObjectMappingTests/JTObjectMappingTests.m
Expand Up @@ -10,6 +10,7 @@
#import "NSObject+JTObjectMapping.h"
#import "JTUserTest.h"
#import "JTSocialNetworkTest.h"
#import "JPNestedArrayTest.h"

@implementation JTObjectMappingTests
@synthesize json, mapping, object;
Expand Down Expand Up @@ -56,6 +57,15 @@ - (void)setUp
@"@bob", @"twitter",
@"bob", @"facebook",
nil], @"social_networks",


[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:@"one", @"two", nil], @"array", nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:@"three", @"four", nil], @"array", nil],
nil], @"nestedArray",

nil];

self.mapping = [NSDictionary dictionaryWithObjectsAndKeys:
Expand All @@ -75,6 +85,10 @@ - (void)setUp
@"twitterID", @"twitter",
@"facebookID", @"facebook",
nil]], @"social_networks",

[JPNestedArrayTest mappingWithKey:@"nestedArray"
mapping:[NSDictionary dictionaryWithObjectsAndKeys:
@"array", @"array", nil]], @"nestedArray",
nil];

self.object = [JTUserTest objectFromJSONObject:json mapping:mapping];
Expand Down Expand Up @@ -154,5 +168,21 @@ - (void)testUsers {
// STAssertEqualObjects(self.object.autoSocialNetwork, network, nil, nil);
// [network release];
//}
//
- (void)testNestedArray {
STAssertTrue([self.object.nestedArray count] == 2, @"Should have two apis", nil);

JPNestedArrayTest *api = [self.object.nestedArray objectAtIndex:0];
STAssertTrue([api isKindOfClass:[JPNestedArrayTest class]], @"%@ != [JPAPITests class]", [api class]);

NSArray *expectedArray = [NSArray arrayWithObjects:@"one", @"two", nil];
STAssertEqualObjects(api.array, expectedArray, nil, nil);

JPNestedArrayTest *api2 = [self.object.nestedArray objectAtIndex:1];
STAssertTrue([api2 isKindOfClass:[JPNestedArrayTest class]], @"%@ != [JPAPITests class]", [api2 class]);

NSArray *expectedArray2 = [NSArray arrayWithObjects:@"three", @"four", nil];
STAssertEqualObjects(api2.array, expectedArray2, nil, nil);
}

@end
1 change: 1 addition & 0 deletions JTObjectMappingTests/JTUserTest.h
Expand Up @@ -22,6 +22,7 @@

@property (nonatomic, copy) NSString *autoString;
@property (nonatomic, retain) NSArray *autoArray;
@property (nonatomic, retain) NSArray *nestedArray;
//@property (nonatomic, retain) JTSocialNetworkTest *autoSocialNetwork;

@property (nonatomic, retain) JTSocialNetworkTest *socialNetwork;
Expand Down
1 change: 1 addition & 0 deletions JTObjectMappingTests/JTUserTest.m
Expand Up @@ -15,5 +15,6 @@ @implementation JTUserTest
@synthesize autoString, autoArray;
//@synthesize autoSocialNetwork;
@synthesize socialNetwork;
@synthesize nestedArray;

@end
11 changes: 7 additions & 4 deletions README.md
Expand Up @@ -73,14 +73,17 @@ For more detailed usage, see **JTObjectMappingTests.m**, will be adding more det
Update Logs
-----------

v1.0.4
- Added auto NSDictionary value to NSObject property mapping with the same key defined
v1.0.5
- Fixed nested array causing crash

v1.0.4
- Added auto NSDictionary value to NSObject property mapping with the same key defined
- Fixed false possible JSON response in NSArray use case

v1.0.3
v1.0.3
- Add raw array JSON response support

v1.0.2
v1.0.2
- Added NSArray support

v1.0.1
Expand Down

0 comments on commit e0427df

Please sign in to comment.