This project is archived and is in readonly mode.
[PATCH] rendering an object as json calls JSON.encode(object) instead of object.to_json
Reported by Diego Carrion | September 18th, 2010 @ 03:15 PM
Given I have the following code:
class User < ActiveRecord::Base
def to_json(options = {})
super options.merge :include => :parent
end end
class UsersController < ActionController::Base
def show
render :json => User.find(params[:id])
end end
the expected behaviour would be to render the user as json including the parent. This is not the current behaviour because today the user is rendered calling ActiveSupport::JSON.encode(user, options) instead of user.to_json(options) . I changed the implementation and nothing did break, so I think there is nothing wrong of changing this. I did also talk with a lot of people and all think calling to_json should be the default behaviour.
A patch is attached.
Comments and changes to this ticket
-
Diego Carrion September 18th, 2010 @ 04:40 PM
- Title changed from rendering an object as json calls JSON.encode(object) instead of object.to_json to [PATCH] rendering an object as json calls JSON.encode(object) instead of object.to_json
-
Diego Carrion September 25th, 2010 @ 03:32 PM
- Assigned user set to José Valim
-
Repository September 27th, 2010 @ 10:12 PM
- State changed from new to resolved
(from [72f37bd8bc5b3beb1e8a2d1ac2de2c045cd0cfd2]) renderer calls object.to_json when rendering :json => object [#5655 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/72f37bd8bc5b3beb1e8a2d1ac2de2c... -
Repository September 27th, 2010 @ 10:22 PM
(from [a56df5b0527cc996108da38a5651e107761d8bea]) renderer calls object.to_json when rendering :json => object [#5655 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/a56df5b0527cc996108da38a5651e1...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 5655 [PATCH] rendering an object as json calls JSON.encode(object) instead of object.to_json (from [72f37bd8bc5b3beb1e8a2d1ac2de2c045cd0cfd2]) rendere...
- 5655 [PATCH] rendering an object as json calls JSON.encode(object) instead of object.to_json (from [a56df5b0527cc996108da38a5651e107761d8bea]) rendere...