Erik Berlin a17ffc3136 [ruby/json] Java generator: raise TypeError for a String key whose to_s is broken
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
2026-11-05 20:39:51 +00:00
..
2026-10-02 14:45:31 +00:00