Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is extracted from #12183 as an isolated PR. I documented the current state of JSON-gem-vs-active-support incompatibility here. Clearly, you cannot currently use the JSON gem's
dump
orgenerate
method in conjunction with ActiveSupport's JSON encoder, otherwise, things may break unexpectedly on certain input at runtime with a cryptic error. This limitation is not currently very well known. It's probably safe to assume that the situation is going to get worse as we move to Ruby 1.9+ (where the JSON gem ships with the stdlib) and as multi_json is being EOL'ed and removed from Rails 4.1 (many gem authors simply replacedMultiJson.dump
with::JSON.{dump,generate}
.To improve the situation, we can do one of the following things:
::JSON.{dump,generate}
to raise an exception when ActiveSupport::JSON is loaded: while this might be ideal from a purist perspective, I'm afraid this is a non-starter – even some of our dependencies are currently using::JSON.{dump,generate}
in their codebase.With this PR, calling
::JSON.{generate,dump}
will invoke the JSON gem's encoder. It will not invoke any of theActiveSupport::JSON
logic, i.e. it will bypassas_json
and ignore any options that it does not natively understand (e.g.only
,except
, etc). Instead of using the ad-hoc approach in #9295, this PR changes our version ofto_json
to add some triage code. The end result is that invoking::JSON.{generate,dump}
will yield the same result before and afterActiveSupport::JSON
is loaded.If I get a 👍 from core, I'll can clean things up, add the changelog, etc.
cc @jeremy