When using multi_json 1.21.0 or later, the following warning is displayed:
The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
MultiJson is deprecated in multi_json 1.21.0 and later; MultiJSON should be used instead.
https://github.com/sferik/multi_json/blob/v1.21.1/CHANGELOG.md#deprecated
Deprecated
- The
MultiJson constant in favor of MultiJSON.
The issue is likely caused by the fact that lib/grape/json.rb only uses ::MultiJson for backend detection.
Steps to reproduce
Confirmed with v3.2.1.
- Add
gem 'multi_json' to Gemfile and run bundle install
- Add
require 'multi_json' to the beginning of lib/grape/json.rb
- Run
bundle exec rspec spec/grape/api_spec.rb --fail-fast
diff --git a/Gemfile b/Gemfile
index 468c73fd..298c0b47 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,6 +7,7 @@ gemspec
group :development, :test do
gem 'builder', require: false
gem 'bundler'
+gem 'multi_json'
gem 'rake'
gem 'rubocop', '1.86.0', require: false
gem 'rubocop-performance', '1.26.1', require: false
diff --git a/lib/grape/json.rb b/lib/grape/json.rb
index a3001453..cb76e21c 100644
--- a/lib/grape/json.rb
+++ b/lib/grape/json.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require 'multi_json'
+
module Grape
if defined?(::MultiJson)
Json = ::MultiJson
Test run results:
Failures:
1) Grape::API.route put allows a(n) Hash json object in params
Failure/Error: __send__ verb, '/', Grape::Json.dump(object), 'CONTENT_TYPE' => 'application/json'
DeprecatedWarningHandler::DeprecationWarning:
The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
# ./spec/grape/api_spec.rb:492:in 'block (6 levels) in <top (required)>'
Finished in 0.09947 seconds (files took 0.21904 seconds to load)
81 examples, 1 failure
Failed examples:
rspec ./spec/grape/api_spec.rb[1:11:9:13] # Grape::API.route put allows a(n) Hash json object in params
Randomized with seed 13003
When using multi_json 1.21.0 or later, the following warning is displayed:
MultiJsonis deprecated in multi_json 1.21.0 and later;MultiJSONshould be used instead.https://github.com/sferik/multi_json/blob/v1.21.1/CHANGELOG.md#deprecated
The issue is likely caused by the fact that lib/grape/json.rb only uses
::MultiJsonfor backend detection.Steps to reproduce
Confirmed with v3.2.1.
gem 'multi_json'to Gemfile and runbundle installrequire 'multi_json'to the beginning of lib/grape/json.rbbundle exec rspec spec/grape/api_spec.rb --fail-fastTest run results: