Skip to content

Commit 5554e66

Browse files
Fix #28
Add a test and fix for issue #28. Value arrays now get successfully parsed using formatters.
1 parent be9a637 commit 5554e66

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

Classes/JSONAPIResourceParser.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ + (void)set:(NSObject <JSONAPIResource> *)resource withDictionary:dictionary {
215215

216216
if ([value isKindOfClass:[NSArray class]]) {
217217
if (format) {
218-
NSMutableArray *temp = [value copy];
219-
for (int i=0; i < [value length]; ++i) {
218+
NSMutableArray *temp = [value mutableCopy];
219+
for (int i = 0; i < [value count]; ++i) {
220220
id xformed;
221221
if ([format getObjectValue:&xformed forString:temp[i] errorDescription:&error]) {
222222
temp[i] = xformed;

Project/JSONAPI/ArticleResource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
@property (nonatomic, strong) NSDate *date;
1818
@property (nonatomic, strong) NSArray *comments;
1919

20+
@property (nonatomic, strong) NSArray *versions;
21+
2022
@end

Project/JSONAPI/ArticleResource.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ + (JSONAPIResourceDescriptor*)descriptor {
3333

3434
[__descriptor hasOne:[PeopleResource class] withName:@"author"];
3535
[__descriptor hasMany:[CommentResource class] withName:@"comments"];
36+
37+
[__descriptor addProperty:@"versions"
38+
withDescription:[[JSONAPIPropertyDescriptor alloc] initWithJsonName:@"versions" withFormat:[NSDateFormatter RFC3339DateFormatter]]];
3639
});
3740

3841
return __descriptor;

Project/JSONAPITests/JSONAPITests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ - (void)testDataArticles {
5555
XCTAssert([article isKindOfClass:[ArticleResource class]], @"Article should be a ArticleResource");
5656
XCTAssertEqualObjects(article.ID, @"1", @"Article id should be 1");
5757
XCTAssertEqualObjects(article.title, @"JSON API paints my bikeshed!", @"Article title should be 'JSON API paints my bikeshed!'");
58+
XCTAssertNotNil(article.versions, @"Article versions should contain an array of dates");
5859
}
5960

6061
- (void)testIncludedPeopleAndComments {

Project/JSONAPITests/main_example.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
"type": "articles",
1212
"id": "1",
1313
"attributes": {
14-
"title": "JSON API paints my bikeshed!"
14+
"title": "JSON API paints my bikeshed!",
15+
"versions": [
16+
"2015-09-01T12:15:00Z",
17+
"2015-08-01T06:15:00Z"
18+
]
1519
},
1620
"relationships": {
1721
"author": {

0 commit comments

Comments
 (0)