Silence remaining multi_json 1.21 "MultiJson constant is deprecated" warning (needs ::MultiJSON + gemspec floor bump?)
Context
multi_json 1.21 renamed the MultiJson module to MultiJSON and deprecated the old constant, emitting:
The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
In sinatra-contrib, lib/sinatra/json.rb references ::MultiJson in two places:
JSON.encode->::MultiJson.dump(object)Base.set :json_encoder { ::MultiJson }
#2169 addresses the companion #encode deprecation (preferring #generate) in a fully backward-compatible way. This issue is about the remaining constant warning, which #2169 deliberately leaves alone because fixing it is not backward compatible.
The tradeoff
::MultiJson -> ::MultiJSON would silence it, but MultiJSON only exists in multi_json >= 1.21, while the gemspec currently allows multi_json >= 0.0.2. So a constant swap implies bumping the dependency floor.
Question for maintainers — which direction do you prefer?
- Bump the floor to
multi_json >= 1.21and use::MultiJSON(drops users on older multi_json). defined?-guarded reference (defined?(::MultiJSON) ? ::MultiJSON : ::MultiJson) to keep broad compatibility at the cost of a small shim.- Drop multi_json in favour of stdlib
JSONas the default encoder — the README already documentsset :json_encoder, JSON, and stdlib JSON has shipped with Ruby for a long time. Removes the dependency entirely.
Happy to open a PR for whichever direction you'd accept.
Source: sinatra/sinatra