Skip to content
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

Make JSON parser swappable #9

Open
dblock opened this issue Oct 4, 2017 · 1 comment
Open

Make JSON parser swappable #9

dblock opened this issue Oct 4, 2017 · 1 comment

Comments

@dblock
Copy link
Collaborator

dblock commented Oct 4, 2017

Want to be able to use multi_json or OJ.

@yuki24
Copy link
Collaborator

yuki24 commented Oct 27, 2017

Both Ruby and Rails allow for swapping the default JSON parser:

require 'json'

JSON.parser
# => JSON::Ext::Parser

JSON.parse '{"foo":1}'
# => {"foo"=>1}

JSON.parser = nil
JSON.parse '{"foo":1}'
# => NoMethodError: undefined method `new' for nil:NilClass

require 'oj'
JSON.parser = Oj
JSON.parse '{"foo":1}'
# => {"foo"=>1}

Oj even has its own mechanism to inject itself to Rails:

require 'active_support/json/encoding'

ActiveSupport::JSON::Encoding.json_encoder
# => ActiveSupport::JSON::Encoding::JSONGemEncoder

require 'oj'
Oj.optimize_rails

ActiveSupport::JSON::Encoding.json_encoder
# => Oj::Rails::Encoder

So I'm not sure if it makes sense for this gem to depend on third-party libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants