Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #349 from Ahti/invalid-json-keypaths-exception

backport exception for invalid JSONKeyPathsByPropertyKey
  • Loading branch information...
commit cf9f2e6ca7c7aa2d78aa7995d5bf42bb83d310ff 2 parents 357c2c2 + 9add845
@robb robb authored
Showing with 9 additions and 10 deletions.
  1. +9 −10 Mantle/MTLJSONAdapter.m
View
19 Mantle/MTLJSONAdapter.m
@@ -144,19 +144,18 @@ - (id)initWithJSONDictionary:(NSDictionary *)JSONDictionary modelClass:(Class)mo
NSSet *propertyKeys = [self.modelClass propertyKeys];
- for (NSString *JSONKeyPath in self.JSONKeyPathsByPropertyKey) {
- if ([propertyKeys containsObject:JSONKeyPath]) continue;
+ for (NSString *mappedPropertyKey in self.JSONKeyPathsByPropertyKey) {
+ if (![propertyKeys containsObject:mappedPropertyKey]) {
+ NSAssert(NO, @"%@ is not a property of %@.", mappedPropertyKey, modelClass);
+ return nil;
+ }
- if (error != NULL) {
- NSDictionary *userInfo = @{
- NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid JSON mapping", nil),
- NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:NSLocalizedString(@"%1$@ could not be parsed because its JSON mapping contains illegal property keys.", nil), modelClass]
- };
+ id value = self.JSONKeyPathsByPropertyKey[mappedPropertyKey];
- *error = [NSError errorWithDomain:MTLJSONAdapterErrorDomain code:MTLJSONAdapterErrorInvalidJSONMapping userInfo:userInfo];
+ if (![value isKindOfClass:NSString.class] && value != NSNull.null) {
+ NSAssert(NO, @"%@ must either map to a JSON key path or NSNull, got: %@.",mappedPropertyKey, value);
+ return nil;
}
-
- return nil;
}
for (NSString *propertyKey in propertyKeys) {
Please sign in to comment.
Something went wrong with that request. Please try again.