rails/rails — Issue #5282: ActiveSupport #to_json core ext should only be allowed on classes that could be represented as Hash or Array with json default engine
Author: oelmekki
Created: 2012-03-05 15:59:51+00:00
State: open

That makes me veeeeeery sad.

```

1.9.2p290 :001 > a = "a".to_json
=> "\"a\""
1.9.2p290 :002 > JSON.parse a
JSON::ParserError: 756: unexpected token at '"a"'
...

1.9.2p290 :003 > a = 1.to_json
=> "1"

1.9.2p290 :004 > JSON.parse a
JSON::ParserError: A JSON text must at least contain two octets!
...

1.9.2p290 :005 > a = true.to_json
=> "true"

1.9.2p290 :006 > JSON.parse a
JSON::ParserError: 756: unexpected token at 'true'
...

1.9.2p290 :007 > a = nil.to_json
=> "null"

1.9.2p290 :008 > JSON.parse a
JSON::ParserError: 756: unexpected token at 'null'
...

1.9.2p290 :009 > ActiveSupport::JSON.engine
=> MultiJson::Engines::JsonGem
```

Shouldn't active_support/core_ext/object/to_json.rb checks if current json engine supports parsing something else than arries and objects before delegating ActiveSupport::JSON on FalseClass, Float, Integer, NilClass, String and TrueClass ?