{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1248","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1248/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1248/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1248/events","html_url":"https://github.com/rails-api/active_model_serializers/pull/1248","id":110110160,"number":1248,"title":"Basic deserialization.","user":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/C:%20JSON%20API","name":"C: JSON API","color":"CCCCCC"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/Feature","name":"Feature","color":"009800"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/V:%200.10.x","name":"V: 0.10.x","color":"bfd4f2"}],"state":"open","locked":false,"assignee":{"login":"joaomdmoura","id":667063,"avatar_url":"https://avatars.githubusercontent.com/u/667063?v=3","gravatar_id":"","url":"https://api.github.com/users/joaomdmoura","html_url":"https://github.com/joaomdmoura","followers_url":"https://api.github.com/users/joaomdmoura/followers","following_url":"https://api.github.com/users/joaomdmoura/following{/other_user}","gists_url":"https://api.github.com/users/joaomdmoura/gists{/gist_id}","starred_url":"https://api.github.com/users/joaomdmoura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joaomdmoura/subscriptions","organizations_url":"https://api.github.com/users/joaomdmoura/orgs","repos_url":"https://api.github.com/users/joaomdmoura/repos","events_url":"https://api.github.com/users/joaomdmoura/events{/privacy}","received_events_url":"https://api.github.com/users/joaomdmoura/received_events","type":"User","site_admin":false},"milestone":null,"comments":20,"created_at":"2015-10-06T21:59:13Z","updated_at":"2015-12-29T21:28:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1248","html_url":"https://github.com/rails-api/active_model_serializers/pull/1248","diff_url":"https://github.com/rails-api/active_model_serializers/pull/1248.diff","patch_url":"https://github.com/rails-api/active_model_serializers/pull/1248.patch"},"body":"# Update:\r\nThis PR offers basic JSON API deserialization through `ActiveModel::Serializer::Adapter::JsonApi::Deserialization.parse(hash, options = {})` which takes a hash ~~or an instance of `ActionController::Parameters`~~ representing a JSON API document (and possibly some options, more on that further down) and returns an `ActiveRecord`-friendly hash, so that you can use it as follows:\r\n```ruby\r\npost_params = ActiveModel::Serializer::Adapter::JsonApi::Deserialization.parse(params.to_h) # or params.to_unsafe_h depending on your rails version\r\n@post = Post.new(post_params)\r\n```\r\n\r\nThe only available option currently is `fields`, which allows for\r\n + whitelisting of fields (attributes and relationships) by providing an array of symbols, and \r\n + specifying the corresponding attribute name on the model when using the `key` option on the association in the serializer, by providing a Hash at the end of the array.\r\nExample:\r\n```ruby\r\nhash = {\r\n  'data' => {\r\n    'type' => 'photos',\r\n    'id' => 'zorglub',\r\n    'attributes' => {\r\n      'title' => 'Ember Hamster',\r\n      'src' => 'http://example.com/images/productivity.png'\r\n    },\r\n    'relationships' => {\r\n      'author' => {\r\n        'data' => nil\r\n      },\r\n      'photographer' => {\r\n        'data' => { 'type' => 'people', 'id' => '9' }\r\n      },\r\n      'comments' => {\r\n        'data' => [\r\n          { 'type' => 'comments', 'id' => '1' },\r\n          { 'type' => 'comments', 'id' => '2' }\r\n        ]\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nparse(hash, fields: [:id, :title, :src, :comments, author: :user])\r\n```\r\nreturns\r\n```ruby\r\n{\r\n  id: 'zorglub',\r\n  src: 'http://example.com/images/productivity.png',\r\n  user_id: nil,\r\n  comment_ids: ['1', '2']\r\n}\r\n```\r\n\r\nNote: It currently does not handle polymorphic associations, but could easily be extended to do so.\r\n\r\n# Initial post:\r\n\r\nThis PR offers basic JSON API deserialization through ~~`ActiveModel::Serializer::Adapter::JsonApi.parse(params_or_hash)`~~ which takes a hash or an instance of `ActionController::Parameters` representing a JSON API document and turns it into an `ActiveRecord`-friendly hash, so that you cas use it as follows:\r\n```ruby\r\npost_params = ActiveModel::Serializer::Adapter::JsonApi.parse(params)\r\n@post = Post.new(post_params)\r\n```\r\n\r\n~~Note that this PR does not support aliased relationships~~ (that is the name of the relationship in the client-issued JSON API document won't be changed). \r\nMoreover, ~~it currently does not support any kind of whitelisting directly~~, although you could simply do `post_params.slice!(:id, :name, :description)` to whitelist or `post_params.except!(:is_admin)` to blacklist.\r\nFinally, ~~it currently fails if the JSON API document is ill-formed.~~\r\n\r\nWe could also make it so that the `parse` method transforms whatever comes its way into a new `ActionController::Parameters` instance, so that people can `require` / `permit` stuff instead of `slice` / `except`."},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/167881452","html_url":"https://github.com/rails-api/active_model_serializers/pull/1248#issuecomment-167881452","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1248","id":167881452,"user":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"created_at":"2015-12-29T21:28:42Z","updated_at":"2015-12-29T21:28:42Z","body":"@bf4: `ActiveModel::Serializers::JSON.from_json` does something totally different, it builds a model from a plain json representation."}}