Closed lexruee closed 9 years ago
Use format json instead of xml. The reason is that Hash.form_xml() does not produce conistent results.
Examples:
1) xml response of a collection with a single user:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <list available="21" end="21" start="20" type="users" uri="/CyberCoachServer/resources/users/"> <links> <link description="previous" href="/CyberCoachServer/resources/users/?start=15&size=5"/> </links> <users> <user username="timon" uri="/CyberCoachServer/resources/users/timon/"/> </users> </list>
Hash.from_xml produces:
{ "list" => { "available"=>"21", "end"=>"21", "start"=>"20", "type"=>"users", "uri"=>"/CyberCoachServer/resources/users/", "links"=> { "link"=> { "description" =>"previous", "href"=>"/CyberCoachServer/resources/users/?start=15&size=5" } }, "users"=> { "user"=> { "username"=>"timon", "uri"=>"/CyberCoachServer/resources/users/timon/" } } } }
2) xml response of a collection with multiple uses:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <list available="21" end="20" start="15" type="users" uri="/CyberCoachServer/resources/users/"> <links> <link description="next" href="/CyberCoachServer/resources/users/?start=20&size=5"/> <link description="previous" href="/CyberCoachServer/resources/users/?start=10&size=5"/> </links> <users> <user username="newyorkfalconstest2" uri="/CyberCoachServer/resources/users/newyorkfalconstest2/"/> <user username="newyorkfalconstest4" uri="/CyberCoachServer/resources/users/newyorkfalconstest4/"/> <user username="polchky" uri="/CyberCoachServer/resources/users/polchky/"/> <user username="test" uri="/CyberCoachServer/resources/users/test/"/> <user username="testtest" uri="/CyberCoachServer/resources/users/testtest/"/> </users> </list>
{ "list"=> { "available"=>"21", "end"=>"20", "start"=>"15", "type"=>"users", "uri"=>"/CyberCoachServer/resources/users/", "links"=> { "link"=>[ {"description"=>"next", "href"=>"/CyberCoachServer/resources/users/?start=20&size=5"}, {"description"=>"previous", "href"=>"/CyberCoachServer/resources/users/?start=10&size=5"} ] }, "users"=> { "user"=> [ { "username"=>"newyorkfalconstest2", "uri"=>"/CyberCoachServer/resources/users/newyorkfalconstest2/"}, { "username"=>"newyorkfalconstest4", "uri"=>"/CyberCoachServer/resources/users/newyorkfalconstest4/"}, { "username"=>"polchky", "uri"=>"/CyberCoachServer/resources/users/polchky/"}, { "username"=>"test", "uri"=>"/CyberCoachServer/resources/users/test/"}, { "username"=>"testtest", "uri"=>"/CyberCoachServer/resources/users/testtest/"} ] } } }
In the first example hash['list']['users']['user'] is a hash and in the second example hash['list']['users']['user'] is a list.
Use format json instead of xml. The reason is that Hash.form_xml() does not produce conistent results.
Examples:
1) xml response of a collection with a single user:
Hash.from_xml produces:
2) xml response of a collection with multiple uses:
Hash.from_xml produces:
In the first example hash['list']['users']['user'] is a hash and in the second example hash['list']['users']['user'] is a list.