Summary
multi_json 1.21.0 deprecated the legacy MultiJson constant in favor of MultiJSON. PR #112 handled this in the serializer (Serializer::MultiJson) by gating on deprecated_gem_version_loaded? and calling ::MultiJSON.parse / ::MultiJSON.generate for multi_json >= 1.21.0.
However, Base#perform_request still calls ::MultiJson.adapter directly, without the same guard. With multi_json >= 1.21.0 installed this emits, on the first JSON response of every process:
The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
Location
In lib/elastic/transport/transport/base.rb, inside perform_request (still present on main, commit d192b57):
# Prevent Float value from automatically becoming BigDecimal when using Oj
load_options = {}
load_options[:mode] = :compat if ::MultiJson.adapter.to_s == "MultiJson::Adapters::Oj"
::MultiJson.adapter is a method call on the legacy constant, which routes through multi_json's deprecation shim and triggers the warning. The serializer at lib/elastic/transport/transport/serializer/multi_json.rb is already guarded; this call site was missed.
Environment
elastic-transport 8.5.2 (and main)
multi_json 1.21.1
- Ruby 4.0.1
Reproduction
require 'multi_json' # 1.21.x
Warning[:deprecated] = true
::MultiJson.adapter
# => warning: The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
In a real app the warning appears at runtime on the first Elasticsearch response with a JSON content-type (once per process, since multi_json warns only once per key).
Suggested fix
Gate the adapter lookup the same way the serializer does, e.g.:
adapter = deprecated_gem_version_loaded? ? ::MultiJson.adapter : ::MultiJSON.adapter
load_options[:mode] = :compat if adapter.to_s.end_with?('Adapters::Oj')
(or expose the existing deprecated_gem_version_loaded? helper to Base, or compare against both "MultiJson::Adapters::Oj" and "MultiJSON::Adapters::Oj").
Issue opened with the help of Claude Code.
Summary
multi_json1.21.0 deprecated the legacyMultiJsonconstant in favor ofMultiJSON. PR #112 handled this in the serializer (Serializer::MultiJson) by gating ondeprecated_gem_version_loaded?and calling::MultiJSON.parse/::MultiJSON.generateformulti_json >= 1.21.0.However,
Base#perform_requeststill calls::MultiJson.adapterdirectly, without the same guard. Withmulti_json >= 1.21.0installed this emits, on the first JSON response of every process:Location
In
lib/elastic/transport/transport/base.rb, insideperform_request(still present onmain, commitd192b57):::MultiJson.adapteris a method call on the legacy constant, which routes throughmulti_json's deprecation shim and triggers the warning. The serializer atlib/elastic/transport/transport/serializer/multi_json.rbis already guarded; this call site was missed.Environment
elastic-transport8.5.2 (andmain)multi_json1.21.1Reproduction
In a real app the warning appears at runtime on the first Elasticsearch response with a JSON
content-type(once per process, sincemulti_jsonwarns only once per key).Suggested fix
Gate the
adapterlookup the same way the serializer does, e.g.:(or expose the existing
deprecated_gem_version_loaded?helper toBase, or compare against both"MultiJson::Adapters::Oj"and"MultiJSON::Adapters::Oj").Issue opened with the help of Claude Code.