Skip to content

MultiJson constant deprecation warning emitted at every boot on 3.4.0 (multi_json 1.21.1) #329

@thomaswitt

Description

@thomaswitt

Summary

opensearch-ruby 3.4.0's default JSON serializer references the deprecated camelCase ::MultiJson constant. As of multi_json 1.21.1 the canonical constant is MultiJSON (all-caps), and MultiJson is a one-time-deprecation forwarder. Every Rails boot that performs an OpenSearch request prints:

The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
MultiJSON.load is deprecated and will be removed in v2.0. Use MultiJSON.parse instead.

PR #290 already removed multi_json from main (now 4.0.0-beta.5+) by switching to the json gem. However, the latest stable release of opensearch-ruby is 3.4.0 (2024-07-11), which still ships the Serializer::MultiJson class unchanged — and 4.0.0 is still in beta, so production users on stable 3.x see the deprecation noise on every boot.

Reproduce

require 'multi_json'      # 1.21.1
require 'opensearch'      # 3.4.0
require 'warning'         # optional, just to surface :deprecated
Warning[:deprecated] = true

OpenSearch::Client.new(url: 'http://localhost:9200').indices.exists?(index: 'whatever')
# => emits the two deprecation warnings above

Source

lib/opensearch/transport/transport/serializer/multi_json.rb at the 3.4.0 tag:

class MultiJson
  include Base

  def load(string, options = {})
    ::MultiJson.load(string, options)   # deprecated constant + deprecated alias
  end

  def dump(object, options = {})
    ::MultiJson.dump(object, options)   # deprecated constant + deprecated alias
  end
end

Two separate deprecations are involved:

  1. The camelCase ::MultiJson constant (deprecated in multi_json 1.21.1 in favor of ::MultiJSON).
  2. The load / dump method aliases (deprecated in favor of parse / generate).

Suggested fix for the 3.x line

Backport a minimal change so 3.x users on multi_json 1.21.1+ don't see deprecation noise:

def load(string, options = {})
  ::MultiJSON.parse(string, options)
end

def dump(object, options = {})
  ::MultiJSON.generate(object, options)
end

Class name Serializer::MultiJson can stay (renaming it would be a breaking change for anyone passing a custom serializer_class:); only the internal delegators need to move to the canonical API.

Workaround

Until a release, downstream apps can prepend a module on OpenSearch::Transport::Transport::Serializer::MultiJson that overrides load / dump to call ::MultiJSON.parse / ::MultiJSON.generate directly. That silences both warnings without touching the gem.

Versions

  • opensearch-ruby 3.4.0
  • multi_json 1.21.1
  • Ruby 3.4.8
  • Rails 8.1.3 (server: Falcon)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions