{"action":"created","issue":{"url":"https://api.github.com/repos/attic-labs/noms/issues/2795","repository_url":"https://api.github.com/repos/attic-labs/noms","labels_url":"https://api.github.com/repos/attic-labs/noms/issues/2795/labels{/name}","comments_url":"https://api.github.com/repos/attic-labs/noms/issues/2795/comments","events_url":"https://api.github.com/repos/attic-labs/noms/issues/2795/events","html_url":"https://github.com/attic-labs/noms/issues/2795","id":186906349,"number":2795,"title":"Support preservation of unnamed field values in go struct marshaling ","user":{"login":"ehalpern","id":852484,"avatar_url":"https://avatars.githubusercontent.com/u/852484?v=3","gravatar_id":"","url":"https://api.github.com/users/ehalpern","html_url":"https://github.com/ehalpern","followers_url":"https://api.github.com/users/ehalpern/followers","following_url":"https://api.github.com/users/ehalpern/following{/other_user}","gists_url":"https://api.github.com/users/ehalpern/gists{/gist_id}","starred_url":"https://api.github.com/users/ehalpern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ehalpern/subscriptions","organizations_url":"https://api.github.com/users/ehalpern/orgs","repos_url":"https://api.github.com/users/ehalpern/repos","events_url":"https://api.github.com/users/ehalpern/events{/privacy}","received_events_url":"https://api.github.com/users/ehalpern/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-02T20:07:21Z","updated_at":"2016-11-02T23:48:55Z","closed_at":null,"body":"Problem: \r\n\r\nWhen unmarshaling a noms struct into a go struct, fields omitted from go struct but present in the noms struct are ignored. If the go struct is then marshaled back to noms, the ignored fields are lost. \r\n\r\nA concrete example of this problem can be seen in the photo-dhash job which adds a dhash field to every photo object. The noms struct looks something like:\r\n\r\n```\r\nstruct Photo {\r\n  id: String,\r\n  title: String \r\n  sizes: Map<struct, {...}, String> \r\n  datePublished...\r\n  dateTaken...\r\n  ...\r\n}\r\n```\r\n\r\nThe go struct looks like: \r\n\r\n```\r\nstruct Photo {\r\n  Id string,\r\n  Sizes map[struct{...}]string, \r\n  Dhash String `noms:\"-\"`\r\n}\r\n```\r\n\r\nProposed Solution:\r\n\r\n- Define a naming convention or annotation that marks a field to hold the original noms value.\r\n- On unmarshal, the field is set to the value read\r\n- On marshal, the go other struct fields are merged with the original value\r\n\r\nThe new go struct would look something like this:\r\n\r\n```\r\nstruct Photo {\r\n  Id string,\r\n  Sizes map[struct{...}]string, \r\n  Dhash String `noms:\"-\"`\r\n  Original types.Value `noms:\"+\"` \r\n}\r\n```\r\n\r\n\r\n   "},"comment":{"url":"https://api.github.com/repos/attic-labs/noms/issues/comments/258033815","html_url":"https://github.com/attic-labs/noms/issues/2795#issuecomment-258033815","issue_url":"https://api.github.com/repos/attic-labs/noms/issues/2795","id":258033815,"user":{"login":"ehalpern","id":852484,"avatar_url":"https://avatars.githubusercontent.com/u/852484?v=3","gravatar_id":"","url":"https://api.github.com/users/ehalpern","html_url":"https://github.com/ehalpern","followers_url":"https://api.github.com/users/ehalpern/followers","following_url":"https://api.github.com/users/ehalpern/following{/other_user}","gists_url":"https://api.github.com/users/ehalpern/gists{/gist_id}","starred_url":"https://api.github.com/users/ehalpern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ehalpern/subscriptions","organizations_url":"https://api.github.com/users/ehalpern/orgs","repos_url":"https://api.github.com/users/ehalpern/repos","events_url":"https://api.github.com/users/ehalpern/events{/privacy}","received_events_url":"https://api.github.com/users/ehalpern/received_events","type":"User","site_admin":false},"created_at":"2016-11-02T23:48:55Z","updated_at":"2016-11-02T23:48:55Z","body":"That's an interesting alternative. I suppose that would be the foundation of the implementation regardless.  \r\n\r\nThe drawback is that it requires the caller to do the extra book keeping rather than handle it automatically. I think there's a good chance that this will be a common pattern due to structural typing in noms."}}
{"actor":{"display_login":"ehalpern"}}