From 0dee9bdad937a74a5667b7781c10e6aab22abee2 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 24 Apr 2025 14:59:52 +0200 Subject: [PATCH 1/2] Bring back the numerous deprecated alias This time with explicit deprecation warnings. --- CHANGES.md | 6 ++++++ lib/json/common.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ece8e0bb..26fed9e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Changes +### 2025-04-24 (2.11.1) + +* Add back `JSON.restore`, `JSON.unparse`, `JSON.fast_unparse` and `JSON.pretty_unparse`. + These were deprecated 16 years ago, but never emited warnings, only undocumented, so are + still used by a few gems. + ### 2025-04-24 (2.11.0) * Optimize Integer generation to be ~1.8x faster. diff --git a/lib/json/common.rb b/lib/json/common.rb index 254ed092..77d024de 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -919,6 +919,50 @@ def dump(obj, anIO = nil, limit = nil, kwargs = nil) end end + # :stopdoc: + # All these were meant to be deprecated circa 2009, but were just set as undocumented + # so usage still exist in the wild. + def unparse(...) + if RUBY_VERSION >= "3.0" + warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated + else + warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1 + end + generate(...) + end + module_function :unparse + + def fast_unparse(...) + if RUBY_VERSION >= "3.0" + warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated + else + warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1 + end + generate(...) + end + module_function :fast_unparse + + def pretty_unparse(...) + if RUBY_VERSION >= "3.0" + warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1, category: :deprecated + else + warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1 + end + pretty_generate(...) + end + module_function :fast_unparse + + def restore(...) + if RUBY_VERSION >= "3.0" + warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1, category: :deprecated + else + warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1 + end + load(...) + end + module_function :restore + # :startdoc: + # JSON::Coder holds a parser and generator configuration. # # module MyApp From 84443e881df0a2a5f86abf95aaec1e43d5fba957 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 24 Apr 2025 15:09:27 +0200 Subject: [PATCH 2/2] Release 2.11.1 --- lib/json/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/json/version.rb b/lib/json/version.rb index 59adffc4..1fa83370 100644 --- a/lib/json/version.rb +++ b/lib/json/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module JSON - VERSION = '2.11.0' + VERSION = '2.11.1' end