Skip to content

Route Grape::Json through the non-deprecated MultiJSON API#2764

Merged
dblock merged 1 commit into
masterfrom
fix/2763-multijson-deprecations
Jun 14, 2026
Merged

Route Grape::Json through the non-deprecated MultiJSON API#2764
dblock merged 1 commit into
masterfrom
fix/2763-multijson-deprecations

Conversation

@ericproulx

@ericproulx ericproulx commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #2763.

Background

multi_json 1.21.0 introduced three deprecations at once (all slated for removal in 2.0):

Deprecated Replacement
MultiJson constant MultiJSON
MultiJSON.load MultiJSON.parse
MultiJSON.dump MultiJSON.generate

lib/grape/json.rb detected the backend via ::MultiJson and Grape::Json.dump resolved to MultiJSON.dump, so anyone on multi_json >= 1.21 saw the deprecation warning reported in #2763:

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

Simply swapping the constant (::MultiJson::MultiJSON) is not enough: Grape::Json.dump/.load would then resolve to the deprecated method names and warn instead. generate/parse are byte-identical replacements for dump/load (verified against both a pre-1.21 and a 1.21 build — only the names changed), so the fix is to route Grape's calls to the non-deprecated names.

What this PR does

1. Grape::Json becomes a small engine-agnostic facade

Grape keeps its own stable dump/parse surface; each backend maps it to its non-deprecated methods:

Backend Grape::Json dump parse
multi_json >= 1.21 (MultiJSON) facade MultiJSON.generate MultiJSON.parse
multi_json < 1.21 (MultiJson) facade MultiJson.dump MultiJson.load
no multi_json = ::JSON JSON.dump JSON.parse

Call sites are unchanged and output is identical on every path, so this is behavior-preserving.

2. Grape::Json.load is removed entirely

Following #2762 (Grape parses request bodies with JSON.parse, never JSON.load, to avoid the json_class/create_additions instantiation vector), load should not appear in the codebase. The two remaining Grape::Json.load test helpers now use parse, and the facade no longer defines load.

3. Legacy multi_json (< 1.21) no longer raises

multi_json < 1.21 has no parse method (only dump/load), so after #2762 Grape::Json.parse would raise NoMethodError on those versions. The legacy branch now maps parseMultiJson.load, fixing that while preserving the user's adapter (oj/yajl).

4. CI covers both multi_json lines

gemfiles/multi_json.gemfile is pinned to >= 1.21 and a new gemfiles/multi_json_1_20.gemfile pins < 1.21; both run the spec/integration/multi_json suite, so the MultiJSON and legacy-MultiJson facades are each exercised. The integration spec keys off the MultiJson constant (defined on both lines) and drives a real Grape API end to end — a JSON request body through the parser into params, and a Hash response through the JSON formatter.

Testing

  • Full suite green on every path:
    • BUNDLE_GEMFILE=gemfiles/multi_json.gemfile bundle exec rspec (>= 1.21, reproduces Deprecation warning for MultiJson when using multi_json 1.21.0 or later #2763): 2323 examples, 0 failures
    • BUNDLE_GEMFILE=gemfiles/multi_json_1_20.gemfile bundle exec rspec spec/integration/multi_json (< 1.21, resolves to 1.20.1): 1 example, 0 failures
    • bundle exec rspec (stdlib JSON fallback): 2322 examples, 0 failures
  • RuboCop clean.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@ericproulx ericproulx force-pushed the fix/2763-multijson-deprecations branch from d965e84 to 80b6d08 Compare June 13, 2026 21:31
@ericproulx ericproulx force-pushed the fix/2763-multijson-deprecations branch 2 times, most recently from 9a594bc to ad360c6 Compare June 13, 2026 21:57
@ericproulx ericproulx requested a review from dblock June 13, 2026 22:01
@ericproulx ericproulx force-pushed the fix/2763-multijson-deprecations branch 3 times, most recently from 9edefc8 to 31e27b9 Compare June 14, 2026 10:54
multi_json 1.21.0 deprecated the `MultiJson` constant (in favor of
`MultiJSON`) and `MultiJSON.dump` (in favor of `generate`), removed in
2.0. Grape detected the backend via `::MultiJson` and called `dump`, so
users on multi_json >= 1.21 saw deprecation warnings (#2763).

Detect `::MultiJSON` and give `Grape::Json` a small facade whose `dump`
delegates to `MultiJSON.generate` (byte-identical output), re-exposing
`parse` since the facade no longer inherits MultiJSON's methods. Behavior
is unchanged; the stdlib fallback is untouched.

Following #2762 (Grape standardizes on `parse`, never `load`, for JSON),
the two remaining `Grape::Json.load` spec helpers move to `parse`, so
`Grape::Json.load` no longer appears anywhere and the facade needs no
`load`.

Also give the legacy multi_json (< 1.21) branch the same facade treatment
mapping dump/parse onto the dump/load it exposes — it has no generate/parse,
so `Grape::Json.parse` would otherwise raise NoMethodError there.

Cover both backends in CI: pin gemfiles/multi_json.gemfile to >= 1.21 and
add gemfiles/multi_json_1_20.gemfile (< 1.21), each running the
spec/integration/multi_json suite. The integration spec keys off the
`MultiJson` constant (defined on both lines) and drives a real Grape API
through the parser and JSON formatter.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the fix/2763-multijson-deprecations branch from 31e27b9 to 39422f9 Compare June 14, 2026 11:14
@dblock dblock merged commit 9c56aa0 into master Jun 14, 2026
67 checks passed
@dblock dblock deleted the fix/2763-multijson-deprecations branch June 14, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation warning for MultiJson when using multi_json 1.21.0 or later

2 participants