{"action":"created","issue":{"url":"https://api.github.com/repos/ohler55/oj/issues/270","labels_url":"https://api.github.com/repos/ohler55/oj/issues/270/labels{/name}","comments_url":"https://api.github.com/repos/ohler55/oj/issues/270/comments","events_url":"https://api.github.com/repos/ohler55/oj/issues/270/events","html_url":"https://github.com/ohler55/oj/issues/270","id":114158461,"number":270,"title":"Oj compatibility with AMS","user":{"login":"erlandsona","id":10421138,"avatar_url":"https://avatars.githubusercontent.com/u/10421138?v=3","gravatar_id":"","url":"https://api.github.com/users/erlandsona","html_url":"https://github.com/erlandsona","followers_url":"https://api.github.com/users/erlandsona/followers","following_url":"https://api.github.com/users/erlandsona/following{/other_user}","gists_url":"https://api.github.com/users/erlandsona/gists{/gist_id}","starred_url":"https://api.github.com/users/erlandsona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erlandsona/subscriptions","organizations_url":"https://api.github.com/users/erlandsona/orgs","repos_url":"https://api.github.com/users/erlandsona/repos","events_url":"https://api.github.com/users/erlandsona/events{/privacy}","received_events_url":"https://api.github.com/users/erlandsona/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-29T22:11:46Z","updated_at":"2015-11-24T16:23:33Z","closed_at":null,"body":"I know this is a repeat of #138 but I wanted to get an update...\r\n\r\nI'm working in a project where for the past couple weeks I've unimplemented AMS because of the difficulty of implementing it with Oj... that said I'm starting to need the capability to nest associations in the JSON output and it would be really nice to have AMS back.\r\n\r\nI'm running...\r\nRails 4.2.4\r\nRuby 2.2.2\r\nLatest Oj\r\nAMS versions [0.8, 0.9, 0.10]...\r\n\r\nThe main issues I'm having are that AMS adds the most latency to response times out of the three JSON options... those being Oj.dump... raw to_json as implemented by the render method... and AMS's overriding of the as_json method I think???\r\n\r\nThe last commit I had with AMS that was sort of working with OJ looked like this...\r\n```ruby\r\ndef index\r\n...\r\n  render json: Oj.dump(\r\n    ActiveModel::ArraySerializer.new(@brands, each_serializer: BrandSerializer)\r\n  )\r\nend\r\n```\r\n\r\nThe issue with this was that there was no root key in the JSON enabling me to add a meta key into the json output... I could solve that like this...\r\n\r\n```ruby\r\ndef index\r\n...\r\n  render json: Oj.dump({\r\n    pagination: pagination(@brands, params[:per_page]),\r\n    brands: ActiveModel::ArraySerializer.new(@brands, each_serializer: BrandSerializer)\r\n  )\r\nend\r\n```\r\nBut that just looks wrong given that I should be able to just write something along the lines of...\r\n\r\n```ruby\r\ndef index\r\n...\r\n  render json: @brands, meta: pagination(@brands, params[:per_page]), meta_key: pagination\r\nend\r\n```\r\n\r\nThe end goal being that AMS can be used to create the appropriate JSON format but Oj's version of the as_json / to_json method would be called by the render method in rails...\r\n\r\nUnfortunately I can't figure out how to get this right without hacks and even without AMS I don't know how to tell whether the Oj_mimic_json gem is actually overriding the rails to_json method or not?\r\n\r\nThe only indicator that Oj is doing anything is when I check the server logs and the output for the controller actions says that the views take 0.2ms as opposed to when I don't have Oj and the views take 150ms or 90ms or whatever... What's wierd is that I can't figure out why even when I have Oj \"turned on\" the actual response times don't change? Regardless of how many ms the views metric shows the response times are generally the same?\r\n\r\nAny thoughts?"},"comment":{"url":"https://api.github.com/repos/ohler55/oj/issues/comments/159321280","html_url":"https://github.com/ohler55/oj/issues/270#issuecomment-159321280","issue_url":"https://api.github.com/repos/ohler55/oj/issues/270","id":159321280,"user":{"login":"ohler55","id":118856,"avatar_url":"https://avatars.githubusercontent.com/u/118856?v=3","gravatar_id":"","url":"https://api.github.com/users/ohler55","html_url":"https://github.com/ohler55","followers_url":"https://api.github.com/users/ohler55/followers","following_url":"https://api.github.com/users/ohler55/following{/other_user}","gists_url":"https://api.github.com/users/ohler55/gists{/gist_id}","starred_url":"https://api.github.com/users/ohler55/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ohler55/subscriptions","organizations_url":"https://api.github.com/users/ohler55/orgs","repos_url":"https://api.github.com/users/ohler55/repos","events_url":"https://api.github.com/users/ohler55/events{/privacy}","received_events_url":"https://api.github.com/users/ohler55/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T16:23:33Z","updated_at":"2015-11-24T16:23:33Z","body":"Are you still interested or should I close this issue?"}}