{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1029","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1029/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1029/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1029/events","html_url":"https://github.com/rails-api/active_model_serializers/pull/1029","id":98357028,"number":1029,"title":"Allow Key Format to Be Overridden and Have Sensible Defaults","user":{"login":"jfelchner","id":285582,"avatar_url":"https://avatars.githubusercontent.com/u/285582?v=3","gravatar_id":"","url":"https://api.github.com/users/jfelchner","html_url":"https://github.com/jfelchner","followers_url":"https://api.github.com/users/jfelchner/followers","following_url":"https://api.github.com/users/jfelchner/following{/other_user}","gists_url":"https://api.github.com/users/jfelchner/gists{/gist_id}","starred_url":"https://api.github.com/users/jfelchner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfelchner/subscriptions","organizations_url":"https://api.github.com/users/jfelchner/orgs","repos_url":"https://api.github.com/users/jfelchner/repos","events_url":"https://api.github.com/users/jfelchner/events{/privacy}","received_events_url":"https://api.github.com/users/jfelchner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-31T09:56:31Z","updated_at":"2015-08-12T07:12:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1029","html_url":"https://github.com/rails-api/active_model_serializers/pull/1029","diff_url":"https://github.com/rails-api/active_model_serializers/pull/1029.diff","patch_url":"https://github.com/rails-api/active_model_serializers/pull/1029.patch"},"body":"### Overriding the Key Format\r\n\r\nYou can specify that serializers use a different style for the format of the\r\nkeys that are sent over. This can be done at the config, class or instance\r\nlevel.\r\n\r\n```ruby\r\n# Global\r\nActiveModel::Serializer.config.key_format = :lower_camel\r\n\r\n# Per Serializer\r\nclass BlogLowerCamelSerializer < ActiveModel::Serializer\r\n  key_format :lower_camel\r\nend\r\n\r\n# Per Instance\r\nBlogSerializer.new(object, key_format: :lower_camel)\r\n```\r\n\r\n#### Currently Supported Key Formats ####\r\n\r\n* `:unaltered`\r\n* `:lower_camel`\r\n* `:underscore`\r\n* `:dasherize`\r\n\r\nThe default key format will be set depending on the adapter that you specify.\r\nFor example, the JSON adapter defaults to `lower_camel` whereas the JSON API\r\nadapter defaults to `dasherize`.  Any other adapter will default to `unaltered`.\r\n\r\nReferences: #534, https://github.com/emberjs/data/issues/3455\r\nCloses: #974 \r\n\r\nMerry Christmas in July everyone. :grinning: :christmas_tree: :santa: \r\n"},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/130194632","html_url":"https://github.com/rails-api/active_model_serializers/pull/1029#issuecomment-130194632","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1029","id":130194632,"user":{"login":"jfelchner","id":285582,"avatar_url":"https://avatars.githubusercontent.com/u/285582?v=3","gravatar_id":"","url":"https://api.github.com/users/jfelchner","html_url":"https://github.com/jfelchner","followers_url":"https://api.github.com/users/jfelchner/followers","following_url":"https://api.github.com/users/jfelchner/following{/other_user}","gists_url":"https://api.github.com/users/jfelchner/gists{/gist_id}","starred_url":"https://api.github.com/users/jfelchner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfelchner/subscriptions","organizations_url":"https://api.github.com/users/jfelchner/orgs","repos_url":"https://api.github.com/users/jfelchner/repos","events_url":"https://api.github.com/users/jfelchner/events{/privacy}","received_events_url":"https://api.github.com/users/jfelchner/received_events","type":"User","site_admin":false},"created_at":"2015-08-12T07:12:30Z","updated_at":"2015-08-12T07:12:30Z","body":"@joaomdmoura ok, I hit a bit of a snag.  I found a bug. :-/\r\n\r\nThe problem is that we don't want to convert keys for hashes that are inside the values for attributes.  Currently it just goes recursively as deep as it needs to to make sure that everything is converted.\r\n\r\nFor example if we have this:\r\n\r\n```ruby\r\n            @second_post = Post.new(\r\n                            id:                   2,\r\n                            title:                'New Post',\r\n                            body:                 'Body',\r\n                            multi_word_attribute: {\r\n                              multiple_words: 'here are some words'\r\n                            })\r\n```\r\n\r\nwe don't want `multiple_words` to become `multiple-words`.  The implementation I have _feels_ really nice, but it obviously won't work.\r\n\r\nMaybe an abstraction is missing or a refactoring is required to make this the \"easy\" change?  I don't have enough familiarity with the codebase so I thought you or someone else might be able to provide some insight."}}