This project is archived and is in readonly mode.

#5655 ✓resolved
Diego Carrion

[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

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=""></a>

People watching this ticket


Referenced by