#2170·sinatra

Silence remaining multi_json 1.21 "MultiJson constant is deprecated" warning (needs ::MultiJSON + gemspec floor bump?)

Author: SeanLFCreated May 27, 2026Updated Jun 1, 2026

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?

  1. Bump the floor to multi_json >= 1.21 and use ::MultiJSON (drops users on older multi_json).
  2. defined?-guarded reference (defined?(::MultiJSON) ? ::MultiJSON : ::MultiJson) to keep broad compatibility at the cost of a small shim.
  3. Drop multi_json in favour of stdlib JSON as the default encoder — the README already documents set :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.