json
json copied to clipboard
Inconsistent behavior of JSON.create_id between JRUBY and MRI, unable to use Symbol
When I use the combination of ":create_additions" and ":symbolize_names" on MRI, than the JSON.create_id on MRI have to be set to a Symbol ":json_class" - because #https://bugs.ruby-lang.org/issues/12219
But when I run the same code in JRuby, I got
Minitest::UnexpectedError: TypeError: no implicit conversion of Symbol into String
json/ext/Parser.java:168:in `initialize'
json/ext/Parser.java:151:in `new'
C:/software/ruby/jruby9k/lib/ruby/gems/shared/gems/json-1.8.3-java/lib/json/common.rb:155:in `parse'
becase JRUBY doesn't support JSON.create_id as Symbol.
Workaround for my code exists,
options[:create_additions] = true
options[:symbolize_names]=true
if defined?(RUBY_ENGINE) && RUBY_ENGINE != 'jruby'
JSON.create_id =JSON.create_id.to_sym
end
object=JSON.parse(json, options)
but I prefer to avoid detection of RUBY_ENGINE and have same behavior for MRI and JRUBY.
Tested on MRI 2.2.1 and JRUBY 9.0.4.0