You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 9, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 9, 2023. It is now read-only.
to_json is used on request, but JSON.generate is used on blank_renderer which produces inconsistent results #30
JSON.generate only allows objects or arrays to be converted to JSON syntax. to_json, however, accepts many Ruby classes even though it acts only as a method for serialization
So a fix could be JSON.generate(obj.respond_to?(:to_json) ? data.to_json : data)? That seems reasonable.
I believe to_json returns a string, so I don't think passing it into JSON.generate() would work. If we are calling to_json exclusively elsewhere, it seems like it could simply be changed to:
Activity
ljharb commentedon Oct 12, 2022
In what way does it not?
davidbarratt commentedon Oct 12, 2022
Objects that aren't hashes will return the
to_svalue.Indeed, the documentation says:
ljharb commentedon Oct 12, 2022
So a fix could be
JSON.generate(obj.respond_to?(:to_json) ? data.to_json : data)? That seems reasonable.davidbarratt commentedon Oct 12, 2022
I believe
to_jsonreturns a string, so I don't think passing it intoJSON.generate()would work. If we are callingto_jsonexclusively elsewhere, it seems like it could simply be changed to:right?
ljharb commentedon Oct 13, 2022
ah right I’m thinking of .as_json