This project is archived and is in readonly mode.
Weird error in Hash.to_json
Reported by mt | September 8th, 2008 @ 06:38 PM | in 2.x
{}.to_json() => "{}" {}.to_json({})
TypeError: wrong argument type Hash (expected Data)
from (irb):4:in `to_json'
from (irb):4
This is in Ruby 1.8.6, Rails 2.1.1...but for some reason reloading the source fixes it:
load '/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/json/encoders/hash.rb' => [] {}.to_json({}) => "{}"
I'm baffled...what's a "Data" and why should to_json be expecting one?
Ah, this is fixed by including the line: require 'json/pure'
So I imagine this is something to do with the FFI between the regular json gem and its C code.
Comments and changes to this ticket
-
Frederick Cheung December 10th, 2008 @ 04:51 PM
- State changed from new to wontfix
The problem is that both json/pure and activesupport define a to_json method on objects. with slightly different semantics. loading those various files overwrites all such methods one way or another.
See also this thread on rails core. Hopefully a resolution will emerge from that. Until then let's close this ticket
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>