{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/883","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/883/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/883/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/883/events","html_url":"https://github.com/rails-api/active_model_serializers/issues/883","id":70743156,"number":883,"title":"[0.10.0rc1] JSON key renaming for existing model attributes","user":{"login":"Leventhan","id":1084226,"avatar_url":"https://avatars.githubusercontent.com/u/1084226?v=3","gravatar_id":"","url":"https://api.github.com/users/Leventhan","html_url":"https://github.com/Leventhan","followers_url":"https://api.github.com/users/Leventhan/followers","following_url":"https://api.github.com/users/Leventhan/following{/other_user}","gists_url":"https://api.github.com/users/Leventhan/gists{/gist_id}","starred_url":"https://api.github.com/users/Leventhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leventhan/subscriptions","organizations_url":"https://api.github.com/users/Leventhan/orgs","repos_url":"https://api.github.com/users/Leventhan/repos","events_url":"https://api.github.com/users/Leventhan/events{/privacy}","received_events_url":"https://api.github.com/users/Leventhan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/0.10.x","name":"0.10.x","color":"bfd4f2"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/Needs%20Bug%20Verification","name":"Needs Bug Verification","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/milestones/5","html_url":"https://github.com/rails-api/active_model_serializers/milestones/0.10","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/milestones/5/labels","id":1011188,"number":5,"title":"0.10","description":"","creator":{"login":"kurko","id":70312,"avatar_url":"https://avatars.githubusercontent.com/u/70312?v=3","gravatar_id":"","url":"https://api.github.com/users/kurko","html_url":"https://github.com/kurko","followers_url":"https://api.github.com/users/kurko/followers","following_url":"https://api.github.com/users/kurko/following{/other_user}","gists_url":"https://api.github.com/users/kurko/gists{/gist_id}","starred_url":"https://api.github.com/users/kurko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kurko/subscriptions","organizations_url":"https://api.github.com/users/kurko/orgs","repos_url":"https://api.github.com/users/kurko/repos","events_url":"https://api.github.com/users/kurko/events{/privacy}","received_events_url":"https://api.github.com/users/kurko/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":4,"state":"open","created_at":"2015-03-08T13:22:14Z","updated_at":"2015-04-27T19:16:42Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2015-04-24T17:18:27Z","updated_at":"2015-04-29T07:49:28Z","closed_at":null,"body":"I have a model with attributes `id` and `slug`.\r\nI'm rendering my `slug` model attribute into `something` in my JSON:\r\n```\r\nattribute :slug, key: :something\r\n```\r\n```\r\n{\r\n\"something\": \"slug-value\",\r\n...\r\n}\r\n```\r\nOkay, that works fine.\r\n\r\nBut if I specify a key name of one of the model's attributes like so:\r\n```\r\nclass AgentTypeSerializer < ActiveModel::Serializer\r\n  attribute :slug, key: :id\r\nend\r\n```\r\n\r\nOutput is: \r\n\r\n```\r\n{\r\nid\": 4,\r\n...\r\n}\r\n```\r\n\r\nIt seems to be pulling the id value instead of renaming the JSON key. Is this a bug?\r\n\r\nFYI, the problem may stem from `method_defined?` here: https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer.rb#L48"},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/97336944","html_url":"https://github.com/rails-api/active_model_serializers/issues/883#issuecomment-97336944","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/883","id":97336944,"user":{"login":"groyoh","id":7434196,"avatar_url":"https://avatars.githubusercontent.com/u/7434196?v=3","gravatar_id":"","url":"https://api.github.com/users/groyoh","html_url":"https://github.com/groyoh","followers_url":"https://api.github.com/users/groyoh/followers","following_url":"https://api.github.com/users/groyoh/following{/other_user}","gists_url":"https://api.github.com/users/groyoh/gists{/gist_id}","starred_url":"https://api.github.com/users/groyoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/groyoh/subscriptions","organizations_url":"https://api.github.com/users/groyoh/orgs","repos_url":"https://api.github.com/users/groyoh/repos","events_url":"https://api.github.com/users/groyoh/events{/privacy}","received_events_url":"https://api.github.com/users/groyoh/received_events","type":"User","site_admin":false},"created_at":"2015-04-29T07:49:28Z","updated_at":"2015-04-29T07:49:28Z","body":"@Leventhan I guess that `method_defined?(key)` here might prevent you to override a function defined in a superclass, e.g.\r\n```ruby\r\nclass PostSerializer < ActiveModel::Serializer\r\n  attribute :title\r\n  def title\r\n    object.title.latinize \r\n  end\r\nend\r\nclass PostPreviewSerializer < PostSerializer\r\n  attribute :title\r\nend\r\n```\r\nAs the serializer does not currently inherit attributes, you would have to call `attribute :title` in the subclass. Without `method_defined?(key)`, you would override the behavior of the `title` method. I don't know if this is the only case though.\r\n\r\nAs for the `id` and `type`, I assume it's only used by the JSON API adapter ([here](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/adapter/json_api.rb#L47) and [here](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/adapter/json_api.rb#L55)). So it might as well be moved to the JSON API adapter. @joaomdmoura what do you think about it? I could work on a PR if necessary."}}