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
a strict version of modelOfClass:fromJSONDictionary: ? #518
Comments
AFAIK the method should already have this “strict” behavior. Are you seeing something different? |
Yes I do. Maybe I didn't make myself clear. When a mapped key is not contained in the JSON, the mapped property will be nil, the model object will be created and the error is nil. Example:
the NSDictionary (abbreviated):
instantiating the model object:
I want the tweet to be nil if one of the properties is nil. |
In this case, |
So @knlr just to confirm, you would like to specify a list of non nullable properties on an MTLModel subclass? Like a |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Consider I'm using modelOfClass:fromJSONDictionary: and I want to be able to tell if something in the mapping went wrong, like a missing key or a type error (e.g. property is a NSNumber but it's a string in the JSON and an NSString is assigned).
I could write validation functions in my model classes checking the validity of each property. Or there could be a 'strict' version of modelOfClass:fromJSONDictionary that returns nil and gives an error when a key was not found or a wrong type is assigned to a property. Is it possible? If so, would you add this?
The text was updated successfully, but these errors were encountered: