Skip to content

MultiJson deprecation warning still emitted from Base#perform_request with multi_json >= 1.21 (PR #112 fix incomplete) #125

Description

@pioz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions