@@ -112,7 +112,7 @@ + (NSDictionary*)dictionaryFor:(NSObject <JSONAPIResource>*)resource {
112
112
if (valueArray.count > 0 ) {
113
113
NSMutableArray *dictionaryArray = [[NSMutableArray alloc ] initWithCapacity: valueArray.count];
114
114
115
- if ([property resourceType ]) {
115
+ if ([property resourceType ] || [(( NSArray *)value).firstObject conformsToProtocol: @protocol (JSONAPIResource)] ) {
116
116
if (linkage == nil ) {
117
117
linkage = [[NSMutableDictionary alloc ] init ];
118
118
}
@@ -279,10 +279,9 @@ + (void)link:(NSObject <JSONAPIResource>*)resource withIncluded:(JSONAPI*)jsonAP
279
279
Class valueClass = nil ;
280
280
if (propertyDescriptor.resourceType ) {
281
281
valueClass = propertyDescriptor.resourceType ;
282
- } else if ([value conformsToProtocol: @protocol (JSONAPIResource)]) {
282
+ } else if ([value conformsToProtocol: @protocol (JSONAPIResource)] || [value isKindOfClass: [ NSArray class ]] ) {
283
283
valueClass = [value class ];
284
284
}
285
- id includedValue = included[[[valueClass descriptor ] type ]];
286
285
287
286
// ordinary attribute
288
287
if (valueClass == nil ) {
@@ -291,20 +290,30 @@ + (void)link:(NSObject <JSONAPIResource>*)resource withIncluded:(JSONAPI*)jsonAP
291
290
} else if ([value isKindOfClass: [NSArray class ]]) {
292
291
NSMutableArray *matched = [value mutableCopy ];
293
292
[value enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
294
- NSObject <JSONAPIResource> *res = obj;
295
- id v = includedValue[res.ID];
296
- if (v != nil ) {
297
- matched[idx] = v;
293
+ if ([obj conformsToProtocol: @protocol (JSONAPIResource)]) {
294
+ NSObject <JSONAPIResource> *res = obj;
295
+ id includedValue = included[[[res.class descriptor ] type ]];
296
+ if (includedValue) {
297
+ id v = includedValue[res.ID];
298
+ if (v != nil ) {
299
+ matched[idx] = v;
300
+ }
301
+ }
298
302
}
299
303
}];
300
304
301
305
[resource setValue: matched forKey: key];
302
306
// has one
303
307
} else if (value != nil ) {
304
- NSObject <JSONAPIResource> *res = value;
305
- id v = includedValue[res.ID];
306
- if (v != nil ) {
307
- [resource setValue: v forKey: key];
308
+ if ([value conformsToProtocol: @protocol (JSONAPIResource)]) {
309
+ id <JSONAPIResource> res = value;
310
+ id includedValue = included[[[res.class descriptor ] type ]];
311
+ if (includedValue) {
312
+ id v = included[[[res.class descriptor ] type ]][res.ID];
313
+ if (v != nil ) {
314
+ [resource setValue: v forKey: key];
315
+ }
316
+ }
308
317
}
309
318
}
310
319
}
0 commit comments