{"action":"created","issue":{"url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/367","labels_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/367/labels{/name}","comments_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/367/comments","events_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/367/events","html_url":"https://github.com/Hearst-DD/ObjectMapper/issues/367","id":126080314,"number":367,"title":"Correct way to fail a mapping?","user":{"login":"scottrhoyt","id":4259250,"avatar_url":"https://avatars.githubusercontent.com/u/4259250?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrhoyt","html_url":"https://github.com/scottrhoyt","followers_url":"https://api.github.com/users/scottrhoyt/followers","following_url":"https://api.github.com/users/scottrhoyt/following{/other_user}","gists_url":"https://api.github.com/users/scottrhoyt/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrhoyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrhoyt/subscriptions","organizations_url":"https://api.github.com/users/scottrhoyt/orgs","repos_url":"https://api.github.com/users/scottrhoyt/repos","events_url":"https://api.github.com/users/scottrhoyt/events{/privacy}","received_events_url":"https://api.github.com/users/scottrhoyt/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-12T02:03:41Z","updated_at":"2016-01-12T15:43:31Z","closed_at":"2016-01-12T15:43:31Z","body":"I have some objects that I would like to fail a mapping if certain keys are `nil`. For instance, if I try to map a server error response to a model object, I'd like to fail if `var id: String!` is `nil`. I thought this should be accomplishable by doing something like:\r\n\r\n    init?(_ map: Map) {\r\n      guard let _ = id else {\r\n        return nil\r\n      }\r\n    }\r\n\r\nIs this the intended way to accomplish this, because all my mappings fail. Is it instead something like:\r\n\r\n    init?(_ map: Map) {\r\n      guard let _ = map[\"id\"].value else {\r\n        return nil\r\n      }\r\n    }\r\n\r\nor \r\n\r\n    init?(_ map: Map) {\r\n      guard let _ = map.JSONDictionary[\"id\"] else {\r\n        return nil\r\n      }\r\n    }"},"comment":{"url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/comments/170951335","html_url":"https://github.com/Hearst-DD/ObjectMapper/issues/367#issuecomment-170951335","issue_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/367","id":170951335,"user":{"login":"tristanhimmelman","id":1562134,"avatar_url":"https://avatars.githubusercontent.com/u/1562134?v=3","gravatar_id":"","url":"https://api.github.com/users/tristanhimmelman","html_url":"https://github.com/tristanhimmelman","followers_url":"https://api.github.com/users/tristanhimmelman/followers","following_url":"https://api.github.com/users/tristanhimmelman/following{/other_user}","gists_url":"https://api.github.com/users/tristanhimmelman/gists{/gist_id}","starred_url":"https://api.github.com/users/tristanhimmelman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tristanhimmelman/subscriptions","organizations_url":"https://api.github.com/users/tristanhimmelman/orgs","repos_url":"https://api.github.com/users/tristanhimmelman/repos","events_url":"https://api.github.com/users/tristanhimmelman/events{/privacy}","received_events_url":"https://api.github.com/users/tristanhimmelman/received_events","type":"User","site_admin":false},"created_at":"2016-01-12T15:43:31Z","updated_at":"2016-01-12T15:43:31Z","body":"Either of the last two ways is fine. I would probably go with `map[\"id\"].value()` though"}}