Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTLJSONAdapter initialize failed when json data contains NSCFArray #259

Closed
bruceli opened this issue Mar 6, 2014 · 5 comments
Closed

MTLJSONAdapter initialize failed when json data contains NSCFArray #259

bruceli opened this issue Mar 6, 2014 · 5 comments

Comments

@bruceli
Copy link

bruceli commented Mar 6, 2014

My model used to work, now it failed in latest version of Mantle. My json data is from api.openweathermap.org, following is a snippet of the data.

weather =     (
            {
        description = mist;
        icon = 50n;
        id = 701;
        main = Mist;
    }
);

The key caused the failure is weather.description. I noticed the serialization failed because of following code added into the initWithJSONDictionary:modelClass:error: method recently.

        if (![value isKindOfClass:NSDictionary.class]) {
            if (error != NULL) {
                NSDictionary *userInfo = @{
                    NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid JSON dictionary", @""),
                    NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:NSLocalizedString(@"%@ could not be parsed because an invalid JSON dictionary was provided for key path \"%@\"", @""), modelClass, JSONKeyPath],
                };

                *error = [NSError errorWithDomain:MTLJSONAdapterErrorDomain code:MTLJSONAdapterErrorInvalidJSONDictionary userInfo:userInfo];
            }

            return nil;
        }

Isn't this a defect?

@robb
Copy link
Member

robb commented Mar 6, 2014

Can you share your +JSONKeyPathsByPropertyKey? Seems like this is related to #257

@bruceli
Copy link
Author

bruceli commented Mar 6, 2014

Here it is.

 + (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
             @"date": @"dt",
             @"locationName": @"name",
             @"humidity": @"main.humidity",
             @"temperature": @"main.temp",
             @"tempHigh": @"main.temp_max",
             @"tempLow": @"main.temp_min",
             @"sunrise": @"sys.sunrise",
             @"sunset": @"sys.sunset",
             @"conditionDescription": @"weather.description",
             @"condition": @"weather.main",
             @"icon": @"weather.icon",
             @"windBearing": @"wind.deg",
             @"windSpeed": @"wind.speed"
             };
}

@robb
Copy link
Member

robb commented Mar 6, 2014

oh, so weather is an array with just one element? Yeah, you seem to be affected by the same regression as #257

@bruceli
Copy link
Author

bruceli commented Mar 6, 2014

Yes, they look very similar. Please duplicate this one if needed.

@jspahrsummers
Copy link
Member

Closing as a dupe of #257.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants