Forum: Ruby on Rails ActiveResource - xml and json format return different results

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2b2b07fe8688479d2559704d4bf8a264?d=identicon&s=25 Szymon Nowak (szimek)
on 2008-12-02 15:53
(Received via mailing list)
Hi,

I'm using Rails 2.1.2. and I wanted to switch ActiveResource format to
JSON and thought that it will work smoothly, but unfortunately it
wasn't the case.

XML and JSON formats generate different objects:
XML version
#<User:0xb7658440 @prefix_options={}, @attributes={"created_at"=>Mon
Nov 28 11...}>

JSON version
#<User:0xb746af5c @prefix_options={}, @attributes={"user"=>#<User:
0xb746ac64 @prefix_options={}, @attributes={"created_at"=>Mon Nov 28
11...}>

As you can see, when using JSON format, the result is nested. Is there
any reason for this? Have it alwyas worked like this or is it a bug?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-02 15:57
(Received via mailing list)
On 2 Dec 2008, at 14:52, szimek wrote:

> Nov 28 11...}>
>
> JSON version
> #<User:0xb746af5c @prefix_options={}, @attributes={"user"=>#<User:
> 0xb746ac64 @prefix_options={}, @attributes={"created_at"=>Mon Nov 28
> 11...}>
>
I suspect this is related to the
ActiveRecord::Base.include_root_in_json  setting

Fred
2b2b07fe8688479d2559704d4bf8a264?d=identicon&s=25 Szymon Nowak (szimek)
on 2008-12-02 21:12
(Received via mailing list)
On 2 Gru, 15:56, Frederick Cheung <frederick.che...@gmail.com> wrote:
> > I'm using Rails 2.1.2. and I wanted to switch ActiveResource format to
> > 0xb746ac64 @prefix_options={}, @attributes={"created_at"=>Mon Nov 28
> > 11...}>
>
> I suspect this is related to the  
> ActiveRecord::Base.include_root_in_json  setting
>
> Fred
>
> > As you can see, when using JSON format, the result is nested. Is there
> > any reason for this? Have it alwyas worked like this or is it a bug?

Thanks!
This topic is locked and can not be replied to.