How do you deal with the conflict between ActiveSupport::JSON and the JSON gem?
Posted
by Luke Francl
on Stack Overflow
See other posts from Stack Overflow
or by Luke Francl
Published on 2009-03-25T23:51:45Z
Indexed on
2010/04/03
23:33 UTC
Read the original article
Hit count: 295
I am stumped with this problem.
ActiveSupport::JSON
defines to_json
on various core objects and so does the JSON gem. However, the implementation is not the same -- the ActiveSupport version takes arguments and the JSON gem version doesn't.
I installed a gem that required the JSON gem and my app broke. The issue is that I'm using to_json
in a controller that returns a list of objects, but I want to control which attributes are returned.
When code anywhere in my system does require 'json'
I get this error message:
TypeError: wrong argument type Hash (expected Data)
I tried a couple of things that I read online to fix it, but nothing worked. I ended up re-writing the gem to use ActiveSupport::JSON.decode
instead of JSON.parse
.
This works but it's not sustainable...I can't be forking gems every time I want to use a gem that requires the JSON gem.
Update: The best solution of this problem is to upgrade to Rails 2.3 or higher, which fixed it.
© Stack Overflow or respective owner