{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/974","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/974/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/974/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/974/events","html_url":"https://github.com/rails-api/active_model_serializers/issues/974","id":91625141,"number":974,"title":"JSON API adapter word separator issue","user":{"login":"hugopeixoto","id":111554,"avatar_url":"https://avatars.githubusercontent.com/u/111554?v=3","gravatar_id":"","url":"https://api.github.com/users/hugopeixoto","html_url":"https://github.com/hugopeixoto","followers_url":"https://api.github.com/users/hugopeixoto/followers","following_url":"https://api.github.com/users/hugopeixoto/following{/other_user}","gists_url":"https://api.github.com/users/hugopeixoto/gists{/gist_id}","starred_url":"https://api.github.com/users/hugopeixoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugopeixoto/subscriptions","organizations_url":"https://api.github.com/users/hugopeixoto/orgs","repos_url":"https://api.github.com/users/hugopeixoto/repos","events_url":"https://api.github.com/users/hugopeixoto/events{/privacy}","received_events_url":"https://api.github.com/users/hugopeixoto/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"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-06-28T18:34:03Z","updated_at":"2015-07-05T09:21:12Z","closed_at":null,"body":"I'm using the JSON API adapter with ember-data and I'm having a small compatibility issue.\r\n\r\nThe new JSON API adapter currently does not transform the attribute keys in any way. I have an attribute with an underscore in my model, it will be left untouched. ember-data/jsonapi looks up attribute names with dash-separated words. This means that these two adapters cannot be used together without changing one of them.\r\n\r\nThe jsonapi spec does not specify that words must be dash-separated, but it does recommend it (https://github.com/rails-api/active_model_serializers/pull/534#issuecomment-116296477, [reference](http://jsonapi.org/recommendations/#naming)). ember-data follows this recommendation (https://github.com/emberjs/data/issues/3455).\r\n\r\nIt would be nice to have a way to use the adapter in the recommended way.\r\nShould this transformation be handled specifically by the jsonapi adapter?\r\nOr should AMS provide a general key transformation option (this feature dropped on 0.10.x: https://github.com/rails-api/active_model_serializers/pull/534)?\r\n\r\nEDIT:\r\n\r\nMy current workaround was to define a base serializer, from which the actual serializers inherit:\r\n\r\n```ruby\r\nclass BaseSerializer < ActiveModel::Serializer\r\n  def attributes *args\r\n    Hash[super.map do |key, value|\r\n      [key.to_s.dasherize.to_sym, value]\r\n    end]\r\n  end\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/118601586","html_url":"https://github.com/rails-api/active_model_serializers/issues/974#issuecomment-118601586","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/974","id":118601586,"user":{"login":"krzkrzkrz","id":390072,"avatar_url":"https://avatars.githubusercontent.com/u/390072?v=3","gravatar_id":"","url":"https://api.github.com/users/krzkrzkrz","html_url":"https://github.com/krzkrzkrz","followers_url":"https://api.github.com/users/krzkrzkrz/followers","following_url":"https://api.github.com/users/krzkrzkrz/following{/other_user}","gists_url":"https://api.github.com/users/krzkrzkrz/gists{/gist_id}","starred_url":"https://api.github.com/users/krzkrzkrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krzkrzkrz/subscriptions","organizations_url":"https://api.github.com/users/krzkrzkrz/orgs","repos_url":"https://api.github.com/users/krzkrzkrz/repos","events_url":"https://api.github.com/users/krzkrzkrz/events{/privacy}","received_events_url":"https://api.github.com/users/krzkrzkrz/received_events","type":"User","site_admin":false},"created_at":"2015-07-05T09:21:12Z","updated_at":"2015-07-05T09:21:12Z","body":"I'm in the same scenario. Using Ember CLI and the JSON API adapter. I've also configured active_model_serializers to use the JSON API format. i.e. setting `ActiveModel::Serializer.config.adapter = :json_api` in a Rails initializer.\r\n\r\nI understand Rails is all about underscores. But if ASM is set to `:json_api` shouldn't it follow the convention of JSON API?\r\n\r\nAt http://jsonapi.org/format/#document-resource-object-attributes search for `first-name`. The JSON API format dictates that attributes be delimited by dashes (`-`). So even if Rails users expect underscores (which is still fine) the output should still be in dashes.\r\n\r\nFor now, the solution suggested by the OP is a workaround:\r\n\r\n```\r\n  def attributes *args\r\n    Hash[super.map do |key, value|\r\n      [key.to_s.dasherize.to_sym, value]\r\n    end]\r\n  end\r\n```"}}