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

Use property default value if json value is null #51

Open
drulang opened this issue Aug 11, 2015 · 2 comments
Open

Use property default value if json value is null #51

drulang opened this issue Aug 11, 2015 · 2 comments

Comments

@drulang
Copy link

drulang commented Aug 11, 2015

Hey,

Just wondering if Realm-JSON can use a property's default value instead of trying to assign NSNull to the property which is causing Realm to crash?

Thanks!
Dru

@matthewcheok
Copy link
Owner

Sounds like valid proposition. Mind submitting a PR?

@komocode
Copy link
Collaborator

If you're using AFNetworking and you're using AFHTTPSessionManager to make your calls, you can do this:

        _manager = [[AFHTTPSessionManager alloc] initWithBaseURL:url];
        AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];
        [responseSerializer setRemovesKeysWithNullValues:YES];
        _manager.responseSerializer = responseSerializer;

This will remove keys that have null values. Then your models should use the default values since the keys with null values are no longer there.

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

No branches or pull requests

3 participants