{"action":"created","comment":{"url":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/comments/42122627","id":42122627,"diff_hunk":"@@ -1,4 +1,5 @@\n defimpl JaSerializer.Formatter, for: JaSerializer.Builder.ResourceIdentifier do\n+  def format(%{id: nil}), do: nil","path":"lib/ja_serializer/formatter/resource_identifier.ex","position":2,"original_position":2,"commit_id":"5fcf664667dc716d04c7bf60bc828c61e62caac9","original_commit_id":"5fcf664667dc716d04c7bf60bc828c61e62caac9","user":{"login":"alanpeabody","id":19368,"avatar_url":"https://avatars.githubusercontent.com/u/19368?v=3","gravatar_id":"","url":"https://api.github.com/users/alanpeabody","html_url":"https://github.com/alanpeabody","followers_url":"https://api.github.com/users/alanpeabody/followers","following_url":"https://api.github.com/users/alanpeabody/following{/other_user}","gists_url":"https://api.github.com/users/alanpeabody/gists{/gist_id}","starred_url":"https://api.github.com/users/alanpeabody/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alanpeabody/subscriptions","organizations_url":"https://api.github.com/users/alanpeabody/orgs","repos_url":"https://api.github.com/users/alanpeabody/repos","events_url":"https://api.github.com/users/alanpeabody/events{/privacy}","received_events_url":"https://api.github.com/users/alanpeabody/received_events","type":"User","site_admin":false},"body":":+1: ","created_at":"2015-10-15T13:20:46Z","updated_at":"2015-10-15T13:20:46Z","html_url":"https://github.com/AgilionApps/ja_serializer/pull/29#discussion_r42122627","pull_request_url":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29","_links":{"self":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/comments/42122627"},"html":{"href":"https://github.com/AgilionApps/ja_serializer/pull/29#discussion_r42122627"},"pull_request":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29","id":47730692,"html_url":"https://github.com/AgilionApps/ja_serializer/pull/29","diff_url":"https://github.com/AgilionApps/ja_serializer/pull/29.diff","patch_url":"https://github.com/AgilionApps/ja_serializer/pull/29.patch","issue_url":"https://api.github.com/repos/AgilionApps/ja_serializer/issues/29","number":29,"state":"open","locked":false,"title":"Fix empty relationships","user":{"login":"dmarkow","id":8009,"avatar_url":"https://avatars.githubusercontent.com/u/8009?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarkow","html_url":"https://github.com/dmarkow","followers_url":"https://api.github.com/users/dmarkow/followers","following_url":"https://api.github.com/users/dmarkow/following{/other_user}","gists_url":"https://api.github.com/users/dmarkow/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarkow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarkow/subscriptions","organizations_url":"https://api.github.com/users/dmarkow/orgs","repos_url":"https://api.github.com/users/dmarkow/repos","events_url":"https://api.github.com/users/dmarkow/events{/privacy}","received_events_url":"https://api.github.com/users/dmarkow/received_events","type":"User","site_admin":false},"body":"Here's my first attempt at fixing #26, though it's definitely not ready to merge yet.\r\n\r\nI agree on the integration test, so I started with that. I added `has_many :likes` and `has_one :excerpt` and set them both to be empty. As expected, the test fails.\r\n\r\nTo handle a blank `has_one`, I updated the `ResourceIdentifier` formatter to format an empty relationship as `nil` (instead of a resource identifier object with a blank `id` field, e.g. ```{\"type\": \"excerpt\", \"id\"; \"\"}```).\r\n\r\nNext, I updated `put_if_present` in the `Utils` module to explicitly add `nil`/ `[]` to `dict` only when it's for the `:data` key. However:\r\n\r\n1. While the JSON API spec only requires explicit `null`/`[]` values when dealing with the `data` object, I don't really like explicitly matching on the `:data` key. But maybe I'm just overthinking it.\r\n2. More importantly, because of this approach (specifically, the guard clause on the `nil` case), `{\"data\": ...}` will be added to **every** relationship in the output, even if we didn't ask it to (e.g. we may have just asked for `has_one :excerpt, link: \"...\"`). And even worse, if we didn't ask for `:data`, it'll be set to `null` even if there really are items in the relationship.\r\n\r\nSo now I'm stuck. The `JaSerializer.Builder.Relationship` struct includes the `:data` key, which defaults to `nil`. If we have an empty has_one relationship, that also sets `:data` to nil. So how do we tell the difference between \"it's nil because we never set it to anything\" vs \"it's nil because that's specifically what we want\"? (This is why I originally suggested using a `:null_value` atom, though I agree that doesn't feel right).","created_at":"2015-10-15T00:06:16Z","updated_at":"2015-10-15T13:20:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e15a83b4b91e28d6bd92df8a0ac0c3af7741c63","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29/commits","review_comments_url":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29/comments","review_comment_url":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/AgilionApps/ja_serializer/issues/29/comments","statuses_url":"https://api.github.com/repos/AgilionApps/ja_serializer/statuses/5fcf664667dc716d04c7bf60bc828c61e62caac9","head":{"label":"dmarkow:fix-empty-relationships","ref":"fix-empty-relationships","sha":"5fcf664667dc716d04c7bf60bc828c61e62caac9","user":{"login":"dmarkow","id":8009,"avatar_url":"https://avatars.githubusercontent.com/u/8009?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarkow","html_url":"https://github.com/dmarkow","followers_url":"https://api.github.com/users/dmarkow/followers","following_url":"https://api.github.com/users/dmarkow/following{/other_user}","gists_url":"https://api.github.com/users/dmarkow/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarkow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarkow/subscriptions","organizations_url":"https://api.github.com/users/dmarkow/orgs","repos_url":"https://api.github.com/users/dmarkow/repos","events_url":"https://api.github.com/users/dmarkow/events{/privacy}","received_events_url":"https://api.github.com/users/dmarkow/received_events","type":"User","site_admin":false},"repo":{"id":44281251,"name":"ja_serializer","full_name":"dmarkow/ja_serializer","owner":{"login":"dmarkow","id":8009,"avatar_url":"https://avatars.githubusercontent.com/u/8009?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarkow","html_url":"https://github.com/dmarkow","followers_url":"https://api.github.com/users/dmarkow/followers","following_url":"https://api.github.com/users/dmarkow/following{/other_user}","gists_url":"https://api.github.com/users/dmarkow/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarkow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarkow/subscriptions","organizations_url":"https://api.github.com/users/dmarkow/orgs","repos_url":"https://api.github.com/users/dmarkow/repos","events_url":"https://api.github.com/users/dmarkow/events{/privacy}","received_events_url":"https://api.github.com/users/dmarkow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dmarkow/ja_serializer","description":"JSONAPI.org Serialization in Elixir.","fork":true,"url":"https://api.github.com/repos/dmarkow/ja_serializer","forks_url":"https://api.github.com/repos/dmarkow/ja_serializer/forks","keys_url":"https://api.github.com/repos/dmarkow/ja_serializer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dmarkow/ja_serializer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dmarkow/ja_serializer/teams","hooks_url":"https://api.github.com/repos/dmarkow/ja_serializer/hooks","issue_events_url":"https://api.github.com/repos/dmarkow/ja_serializer/issues/events{/number}","events_url":"https://api.github.com/repos/dmarkow/ja_serializer/events","assignees_url":"https://api.github.com/repos/dmarkow/ja_serializer/assignees{/user}","branches_url":"https://api.github.com/repos/dmarkow/ja_serializer/branches{/branch}","tags_url":"https://api.github.com/repos/dmarkow/ja_serializer/tags","blobs_url":"https://api.github.com/repos/dmarkow/ja_serializer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dmarkow/ja_serializer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dmarkow/ja_serializer/git/refs{/sha}","trees_url":"https://api.github.com/repos/dmarkow/ja_serializer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dmarkow/ja_serializer/statuses/{sha}","languages_url":"https://api.github.com/repos/dmarkow/ja_serializer/languages","stargazers_url":"https://api.github.com/repos/dmarkow/ja_serializer/stargazers","contributors_url":"https://api.github.com/repos/dmarkow/ja_serializer/contributors","subscribers_url":"https://api.github.com/repos/dmarkow/ja_serializer/subscribers","subscription_url":"https://api.github.com/repos/dmarkow/ja_serializer/subscription","commits_url":"https://api.github.com/repos/dmarkow/ja_serializer/commits{/sha}","git_commits_url":"https://api.github.com/repos/dmarkow/ja_serializer/git/commits{/sha}","comments_url":"https://api.github.com/repos/dmarkow/ja_serializer/comments{/number}","issue_comment_url":"https://api.github.com/repos/dmarkow/ja_serializer/issues/comments{/number}","contents_url":"https://api.github.com/repos/dmarkow/ja_serializer/contents/{+path}","compare_url":"https://api.github.com/repos/dmarkow/ja_serializer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dmarkow/ja_serializer/merges","archive_url":"https://api.github.com/repos/dmarkow/ja_serializer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dmarkow/ja_serializer/downloads","issues_url":"https://api.github.com/repos/dmarkow/ja_serializer/issues{/number}","pulls_url":"https://api.github.com/repos/dmarkow/ja_serializer/pulls{/number}","milestones_url":"https://api.github.com/repos/dmarkow/ja_serializer/milestones{/number}","notifications_url":"https://api.github.com/repos/dmarkow/ja_serializer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dmarkow/ja_serializer/labels{/name}","releases_url":"https://api.github.com/repos/dmarkow/ja_serializer/releases{/id}","created_at":"2015-10-14T23:07:04Z","updated_at":"2015-10-14T23:07:07Z","pushed_at":"2015-10-14T23:42:37Z","git_url":"git://github.com/dmarkow/ja_serializer.git","ssh_url":"git@github.com:dmarkow/ja_serializer.git","clone_url":"https://github.com/dmarkow/ja_serializer.git","svn_url":"https://github.com/dmarkow/ja_serializer","homepage":"","size":273,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"AgilionApps:master","ref":"master","sha":"6e679ea38faa97c4f6d9ef7e1d72acc5ede0d2dc","user":{"login":"AgilionApps","id":590327,"avatar_url":"https://avatars.githubusercontent.com/u/590327?v=3","gravatar_id":"","url":"https://api.github.com/users/AgilionApps","html_url":"https://github.com/AgilionApps","followers_url":"https://api.github.com/users/AgilionApps/followers","following_url":"https://api.github.com/users/AgilionApps/following{/other_user}","gists_url":"https://api.github.com/users/AgilionApps/gists{/gist_id}","starred_url":"https://api.github.com/users/AgilionApps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgilionApps/subscriptions","organizations_url":"https://api.github.com/users/AgilionApps/orgs","repos_url":"https://api.github.com/users/AgilionApps/repos","events_url":"https://api.github.com/users/AgilionApps/events{/privacy}","received_events_url":"https://api.github.com/users/AgilionApps/received_events","type":"Organization","site_admin":false},"repo":{"id":37425270,"name":"ja_serializer","full_name":"AgilionApps/ja_serializer","owner":{"login":"AgilionApps","id":590327,"avatar_url":"https://avatars.githubusercontent.com/u/590327?v=3","gravatar_id":"","url":"https://api.github.com/users/AgilionApps","html_url":"https://github.com/AgilionApps","followers_url":"https://api.github.com/users/AgilionApps/followers","following_url":"https://api.github.com/users/AgilionApps/following{/other_user}","gists_url":"https://api.github.com/users/AgilionApps/gists{/gist_id}","starred_url":"https://api.github.com/users/AgilionApps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgilionApps/subscriptions","organizations_url":"https://api.github.com/users/AgilionApps/orgs","repos_url":"https://api.github.com/users/AgilionApps/repos","events_url":"https://api.github.com/users/AgilionApps/events{/privacy}","received_events_url":"https://api.github.com/users/AgilionApps/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AgilionApps/ja_serializer","description":"JSONAPI.org Serialization in Elixir.","fork":false,"url":"https://api.github.com/repos/AgilionApps/ja_serializer","forks_url":"https://api.github.com/repos/AgilionApps/ja_serializer/forks","keys_url":"https://api.github.com/repos/AgilionApps/ja_serializer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AgilionApps/ja_serializer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AgilionApps/ja_serializer/teams","hooks_url":"https://api.github.com/repos/AgilionApps/ja_serializer/hooks","issue_events_url":"https://api.github.com/repos/AgilionApps/ja_serializer/issues/events{/number}","events_url":"https://api.github.com/repos/AgilionApps/ja_serializer/events","assignees_url":"https://api.github.com/repos/AgilionApps/ja_serializer/assignees{/user}","branches_url":"https://api.github.com/repos/AgilionApps/ja_serializer/branches{/branch}","tags_url":"https://api.github.com/repos/AgilionApps/ja_serializer/tags","blobs_url":"https://api.github.com/repos/AgilionApps/ja_serializer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AgilionApps/ja_serializer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AgilionApps/ja_serializer/git/refs{/sha}","trees_url":"https://api.github.com/repos/AgilionApps/ja_serializer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AgilionApps/ja_serializer/statuses/{sha}","languages_url":"https://api.github.com/repos/AgilionApps/ja_serializer/languages","stargazers_url":"https://api.github.com/repos/AgilionApps/ja_serializer/stargazers","contributors_url":"https://api.github.com/repos/AgilionApps/ja_serializer/contributors","subscribers_url":"https://api.github.com/repos/AgilionApps/ja_serializer/subscribers","subscription_url":"https://api.github.com/repos/AgilionApps/ja_serializer/subscription","commits_url":"https://api.github.com/repos/AgilionApps/ja_serializer/commits{/sha}","git_commits_url":"https://api.github.com/repos/AgilionApps/ja_serializer/git/commits{/sha}","comments_url":"https://api.github.com/repos/AgilionApps/ja_serializer/comments{/number}","issue_comment_url":"https://api.github.com/repos/AgilionApps/ja_serializer/issues/comments{/number}","contents_url":"https://api.github.com/repos/AgilionApps/ja_serializer/contents/{+path}","compare_url":"https://api.github.com/repos/AgilionApps/ja_serializer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AgilionApps/ja_serializer/merges","archive_url":"https://api.github.com/repos/AgilionApps/ja_serializer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AgilionApps/ja_serializer/downloads","issues_url":"https://api.github.com/repos/AgilionApps/ja_serializer/issues{/number}","pulls_url":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls{/number}","milestones_url":"https://api.github.com/repos/AgilionApps/ja_serializer/milestones{/number}","notifications_url":"https://api.github.com/repos/AgilionApps/ja_serializer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AgilionApps/ja_serializer/labels{/name}","releases_url":"https://api.github.com/repos/AgilionApps/ja_serializer/releases{/id}","created_at":"2015-06-14T18:57:59Z","updated_at":"2015-10-13T22:26:27Z","pushed_at":"2015-10-15T00:06:16Z","git_url":"git://github.com/AgilionApps/ja_serializer.git","ssh_url":"git@github.com:AgilionApps/ja_serializer.git","clone_url":"https://github.com/AgilionApps/ja_serializer.git","svn_url":"https://github.com/AgilionApps/ja_serializer","homepage":"","size":273,"stargazers_count":38,"watchers_count":38,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":9,"forks":9,"open_issues":9,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29"},"html":{"href":"https://github.com/AgilionApps/ja_serializer/pull/29"},"issue":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/issues/29"},"comments":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/AgilionApps/ja_serializer/statuses/5fcf664667dc716d04c7bf60bc828c61e62caac9"}}}}