Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveResource is not parsing JSON correct

#5867

It seems that ActiveResource is encapsulating the received object, adding a parent. This makes the received object having no known attributes.
I assume the problem is in the client and not the server. Simple examples from the console (as a client):

self.format = :xml

ruby-1.9.2-p0 > Link.first
=> #<Link:0x00000101c3d4d8 @attributes={"created_at"=>2010-10-25 14:49:16 UTC, "id"=>1, "name"=>"The link", "number"=>1, "updated_at"=>2010-10-25 14:49:16 UTC}, @prefix_options={}>

self.format = :json

ruby-1.9.2-p0 > Link.first
=> #<Link:0x00000100c67680 @attributes={"link"=>#<Link:0x00000100c66cf8 @attributes={"created_at"=>"2010-10-25T14:49:16Z", "id"=>1, "name"=>"The link", "number"=>1, "updated_at"=>"2010-10-25T14:49:16Z"}, @prefix_options={}>}, @prefix_options={}>

Simple examples from the browser (from the server):
http://localhost:3000/links/1.xml

<link>
  <created-at type="datetime">2010-10-25T14:49:16Z</created-at>
  <id type="integer">1</id>
  <name>The link</name>
  <number type="integer">1</number>
  <updated-at type="datetime">2010-10-25T14:49:16Z</updated-at>
</link>

http://localhost:3000/links/1.json

{"link":{"created_at":"2010-10-25T14:49:16Z","id":1,"name":"The link","number":1,"updated_at":"2010-10-25T14:49:16Z"}}

Reported by stonefield · October 26th, 2010 @ 09:01 AM

State: open
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Denis Odorcic
    Denis Odorcic
    • Tag changed from activeresource, json to activeresource, json, patch, verified

    Verified that ActiveResource JSON is not working at all. Resource.include_root_in_json was defaulted to true in #3770 [PATCH] Fix changing ActiveModel include_root_in_json = true to default but wasn't handled when decoding in ActiveResource. I've attached is a patch which does so.

    I also had to fix the tests in format_test.rb as they were incorrectly encoding objects for JSON, and relying on a specific way that XML decodes its objects to get the tests to pass. Feedback on what I did with the tests would be good.

    October 28th, 2010 @ 04:09 AM

  2. stonefield
    stonefield

    Thanks Denis,

    I applied the patch, and it seems to work correctly.
    I also reviewed the tests and I think they look good, but I might not be the right person to verify those.

    October 28th, 2010 @ 11:04 AM

  3. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to open
    • Assigned user set to José Valim
    • Importance changed from to Low

    October 28th, 2010 @ 11:12 AM

  4. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    November 1st, 2010 @ 05:05 PM

  5. Denis Odorcic
    Denis Odorcic
    • Tag set to activeresource, json

    No love for ActiveResource and JSON eh? :( Ran into this again today at work which reminded me about the ticket.

    November 24th, 2010 @ 09:51 PM

  6. rails
    rails

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 26th, 2011 @ 12:00 AM

  7. rails
    rails
    • State changed from open to stale

    February 26th, 2011 @ 12:00 AM

  8. stonefield
    stonefield

    Add the patch, please.
    Tests viewed and seems good.
    Verified that the patch is working.
    Have system in production with this code.

    February 27th, 2011 @ 04:47 AM

  9. Denis Odorcic
    Denis Odorcic
    • State changed from stale to open

    I guess this should still be in [state:open] then since there hasn't been any change to ActiveResource JSON decoding.

    February 28th, 2011 @ 07:01 PM