mirror of
https://github.com/ruby/ruby.git
synced 2026-11-08 01:20:26 +08:00
When a Hash key is a String subclass, both generators call its to_s.
generator.c raises a TypeError in convert_string_subclass if to_s
doesn't return a String. The Java generator passed the result on, then
fell back to TypeConverter.convertToType, which returned the key itself
because it already is a String. So JSON.generate(s => 1) produced
{"test":1} on JRuby instead of raising.
Raise the same TypeError, with the same message, in castKey. The class
names go through to_s like PRIsVALUE does, so anonymous classes show as
#<Class:0x...> the way they do on CRuby.
This lets test_string_subclass_with_broken_to_s run on JRuby.
Part of https://github.com/ruby/json/issues/1123
https://github.com/ruby/json/commit/cf987b116d