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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

activeresource xml/json encoding inconsistency

#2456

the activeresource encoding for xml/json seem to be inconsistent: xml will incude the element name as root

from activeresource/base.rb

self.class.format.encode(attributes, {:root => self.class.element_name})

whereas json will use

self.class.format.encode(attributes, options)

so when an activeresource gets saved, the decoded parameters (on the REST API side) are different, e.g.

{"city"=>nil, "name"=>"Foo Bar" }   (JSON) vs.
{"person" => { "city=>nil, "name"=> "Foo Bar" } } (XML)

so when using json, i can't just use Person.find().update_attributes(params[:person]) in my controller.

is this intentional? looks like a bug.

Reported by Jan Berkel · April 8th, 2009 @ 02:03 PM

State: resolved
Milestone: 2.x
Assigned to: Ryan Bigg Ryan Bigg
Importance: none

Activity

  1. Steve St. Martin
    Steve St. Martin
    • Assigned user set to Ryan Bigg

    this issue can be solved with:

      ActiveRecord::Base.include_root_in_json = true
    

    can be marked as invalid

    April 16th, 2010 @ 12:12 AM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to resolved

    April 16th, 2010 @ 01:25 AM

  3. bingbing