nicklockwood / AutoCoding

AutoCoding is a category on NSObject that provides automatic support for NSCoding and NSCopying to every object.
Other
1.07k stars 131 forks source link

Added check for NSNull pointer types being assigned by json parsing f… #19

Closed rohitggarg closed 8 years ago

rohitggarg commented 9 years ago

…rameworks, if they work alongside autocoding. Currently we are using AFNetworking JSON parser which gives us [NSNull null] value for null json values. Strings are the only possible candidates in case of jsons, but nested object parsing can also have null pointers different than the standard objective-c nil. Due to this, de-serialization of older archives was failing in our project.

rohitggarg commented 9 years ago

Anyone who is looking at this? please reply!

nicklockwood commented 9 years ago

If the type is NSString and you pass NSNull, it's the wrong type. I understand that it's inconvenient because this is common with JSON data, but if you put NSNull in your data model and then try to use it as an NSString, your app will crash, so it's correct to reject it.

If you're sure that it's fine to insert nulls in your data model, you could always set secureSupported to false. Alternatively, you could pre-process your JSON to strip the nulls, or use a JSON library that already has that feature.

rohitggarg commented 9 years ago

Hi Nick,

I saw the comment but I would say its not against the rules to allow [NSNull null] object check here.

Directly from Apple http://developer.apple.com/documentation/Cocoa/Conceptual/NumbersandValues/Articles/Null.html: "The NSNull class defines a singleton object you use to represent null values in situations where nil is prohibited as a value (typically in a collection object such as an array or a dictionary)."

Everybody who codes with Objective C and deals with JSON or Storage data is aware of the fact that nil can't be assigned to these variables. Therefore, I still think the patch that I sent you is valid. Its up to you to merge it or reject it although but I would still like to keep my fork :)

On Wed, Oct 21, 2015 at 2:43 PM, Nick Lockwood notifications@github.com wrote:

If the type is NSString and you pass NSNull, it's the wrong type. I understand that it's inconvenient because this is common with JSON data, but if you put NSNull in your data model and then try to use it as an NSString, your app will crash, so it's correct to reject it.

If you're sure that it's fine to insert nulls in your data model, you could always set secureSupported to false. Alternatively, you could pre-process your JSON to strip the nulls, or use a JSON library that already has that feature.

— Reply to this email directly or view it on GitHub https://github.com/nicklockwood/AutoCoding/pull/19#issuecomment-149829601 .