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:
- The camelCase
::MultiJson constant (deprecated in multi_json 1.21.1 in favor of ::MultiJSON).
- 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)
Summary
opensearch-ruby3.4.0's default JSON serializer references the deprecated camelCase::MultiJsonconstant. As ofmulti_json1.21.1 the canonical constant isMultiJSON(all-caps), andMultiJsonis a one-time-deprecation forwarder. Every Rails boot that performs an OpenSearch request prints:PR #290 already removed
multi_jsonfrommain(now4.0.0-beta.5+) by switching to thejsongem. However, the latest stable release ofopensearch-rubyis 3.4.0 (2024-07-11), which still ships theSerializer::MultiJsonclass unchanged — and4.0.0is still in beta, so production users on stable 3.x see the deprecation noise on every boot.Reproduce
Source
lib/opensearch/transport/transport/serializer/multi_json.rbat the 3.4.0 tag:Two separate deprecations are involved:
::MultiJsonconstant (deprecated inmulti_json1.21.1 in favor of::MultiJSON).load/dumpmethod aliases (deprecated in favor ofparse/generate).Suggested fix for the 3.x line
Backport a minimal change so 3.x users on
multi_json1.21.1+ don't see deprecation noise:Class name
Serializer::MultiJsoncan stay (renaming it would be a breaking change for anyone passing a customserializer_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::MultiJsonthat overridesload/dumpto call::MultiJSON.parse/::MultiJSON.generatedirectly. That silences both warnings without touching the gem.Versions
opensearch-ruby3.4.0multi_json1.21.1