New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object.as_json
is too optimistic and causes errors in 3rd party code.
#51626
Comments
A safer default might be this: class Object
def as_json(options = nil) # :nodoc:
if respond_to?(:to_hash)
to_hash.as_json(options)
else
self.to_s
end
end
end |
I've also seen this reported to sidekiq a few times:
This was eventually fixed by implementing a custom |
The problem with See https://zverok.space/blog/2016-01-18-implicit-vs-expicit.html for a good summary of the differences. |
This monkey patch is dangerous:
rails/activesupport/lib/active_support/core_ext/object/json.rb
Lines 58 to 66 in 82054e8
Specifically, I've seen this issue crop up a number of times. A casual search yields issues that appear to be related:
#to_json
. #51202ActionController::Base#to_json
fails withSystemStackOverflow
. #43040I don't think
as_json
should be monkey patched intoObject
like this. The default behaviour of usingto_s
is safer. Alternatively, objects that refer to themselves (circular references) should be handled correctly.The text was updated successfully, but these errors were encountered: