{"action":"created","issue":{"url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/282","labels_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/282/labels{/name}","comments_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/282/comments","events_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/282/events","html_url":"https://github.com/Hearst-DD/ObjectMapper/issues/282","id":115330413,"number":282,"title":"Unidirectional (To JSON) mapping with immutable model object","user":{"login":"nmccann","id":3238769,"avatar_url":"https://avatars.githubusercontent.com/u/3238769?v=3","gravatar_id":"","url":"https://api.github.com/users/nmccann","html_url":"https://github.com/nmccann","followers_url":"https://api.github.com/users/nmccann/followers","following_url":"https://api.github.com/users/nmccann/following{/other_user}","gists_url":"https://api.github.com/users/nmccann/gists{/gist_id}","starred_url":"https://api.github.com/users/nmccann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmccann/subscriptions","organizations_url":"https://api.github.com/users/nmccann/orgs","repos_url":"https://api.github.com/users/nmccann/repos","events_url":"https://api.github.com/users/nmccann/events{/privacy}","received_events_url":"https://api.github.com/users/nmccann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-05T17:11:41Z","updated_at":"2016-01-20T02:06:56Z","closed_at":null,"body":"Hi,\r\nI recently ran into the following issue in my project: I have a request object that I need to convert to JSON, with the (self-imposed) limitations that the object should be immutable.\r\n\r\nSo far I've had no problem accomplishing this with response objects (From JSON) and ObjectMapper, but when trying to accomplish the same thing with request objects (ones that will only ever be mapped To JSON), I ran into the issue that ObjectMapper expects a `Mappable` object to support mapping from and to JSON. This means that properties have to be `var` so that they can be changed when mapping from JSON.\r\n\r\n#42 showed me that it is possible to provide different mappings when mapping to JSON vs. from JSON, but that seems to assume that the properties will still be `vars`.\r\n\r\nSo far I've implemented the following workaround:\r\n\r\n```\r\nstruct InviteRequest {\r\n  let golferId: Int\r\n  let customerId: Int\r\n}\r\n\r\nextension InviteRequest: Mappable {\r\n  var mappingGolferId: Int {\r\n    get {\r\n      return golferId\r\n    }\r\n    \r\n    set {}\r\n  }\r\n  \r\n  var mappingCustomerId: Int {\r\n    get {\r\n      return customerId\r\n    }\r\n    \r\n    set {}\r\n  }\r\n  \r\n  init?(_ map: Map) {\r\n    fatalError()\r\n  }\r\n  \r\n  mutating func mapping(map: Map) {\r\n    mappingGolferId    <- map[\"id\"]\r\n    mappingCustomerId  <- map[\"customerId\"]\r\n  }\r\n}\r\n```\r\n\r\nThis isn't ideal because it requires a lot of extra boilerplate code. The `init` method is particularly frustrating because `fatalError()` yields a warning that the method isn't called, while omitting it causes an error that the object's properties are not initialized.\r\n\r\nPerhaps there is a better workaround for this, but it would be nice if ObjectMapper better supported the case where a model object is only being used for mapping to JSON - perhaps by providing separate protocols, or support for something like:\r\n\r\n```\r\nmap[\"id\"] = golferId\r\nmap[\"customerId\"] = customerId\r\n```\r\n\r\nThank you for your time,\r\nNoah\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/comments/173060770","html_url":"https://github.com/Hearst-DD/ObjectMapper/issues/282#issuecomment-173060770","issue_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/282","id":173060770,"user":{"login":"nikita-leonov","id":991541,"avatar_url":"https://avatars.githubusercontent.com/u/991541?v=3","gravatar_id":"","url":"https://api.github.com/users/nikita-leonov","html_url":"https://github.com/nikita-leonov","followers_url":"https://api.github.com/users/nikita-leonov/followers","following_url":"https://api.github.com/users/nikita-leonov/following{/other_user}","gists_url":"https://api.github.com/users/nikita-leonov/gists{/gist_id}","starred_url":"https://api.github.com/users/nikita-leonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikita-leonov/subscriptions","organizations_url":"https://api.github.com/users/nikita-leonov/orgs","repos_url":"https://api.github.com/users/nikita-leonov/repos","events_url":"https://api.github.com/users/nikita-leonov/events{/privacy}","received_events_url":"https://api.github.com/users/nikita-leonov/received_events","type":"User","site_admin":false},"created_at":"2016-01-20T02:06:56Z","updated_at":"2016-01-20T02:06:56Z","body":"There are hidden section in README.md that was add before but was hidden afterward. Checked raw source of it for a `Mapping Immutable Properties`. I am actually curious why it was done like this? @tristanhimmelman "}}