Parser crash if resource descriptor not defined
BenjaminDigeon opened this issue · comments
Benjamin Digeon commented
When a ressource descriptor is not defined the JSONAPIResourceParser
crash
The problem is in JSONAPIResourceParser.m
on the branch json-api-v1.0-final
+ (id <JSONAPIResource>)parseResource:(NSDictionary*)dictionary {
NSString *type = dictionary[@"type"] ?: @"";
JSONAPIResourceDescriptor *descriptor = [JSONAPIResourceDescriptor forLinkedType:type];
NSObject <JSONAPIResource> *resource = [[descriptor resourceClass] alloc];
[self set:resource withDictionary:dictionary];
return resource;
}
If an JSONAPIResourceDescriptor
is not defined by for the ressource then parseResource
return nil
And adding nil
to an NSMutableArray
+ (NSArray*)parseResources:(NSArray*)array {
NSMutableArray *mutableArray = @[].mutableCopy;
for (NSDictionary *dictionary in array) {
[mutableArray addObject:[self parseResource:dictionary]];
}
return mutableArray;
}
Give a nice
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
If a ressource descriptor is not defined for a ressource it should be ignored not crashing the app.