flori / json

JSON implementation for Ruby
https://flori.github.io/json
Other
669 stars 322 forks source link

Getting `TypeError: wrong argument type JSON::Pure::Generator::State (expected Data)` from json/pure when called Hash.`to_json` with Fixnum data #198

Open johnvoloski opened 10 years ago

johnvoloski commented 10 years ago
some_hash = { 'jsonrpc' => 'xxxx', 'jsonversion' => 1 }
some_hash.to_json

wrong argument type JSON::Pure::Generator::State(expected Data) (TypeError)

I solved the problem implementing: lib/json/pure/generator.rb:413

class Fixnum
  def to_json(*) to_s end
end
flori commented 10 years ago

Fixnum already has an implementation of the to_json method via its superclass Integer.

I cannot reproduce your problem. Can you provide more information like json and ruby versions, platforms, etc., and the value of JSON.state ? Does the problem crop up, if you only require json or do you need to require anything else?