From 14d85ad2fc91fcb070ea519011b7c1858d8297c2 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 24 Apr 2025 18:10:25 +0200 Subject: [PATCH 1/2] Stop referencing `JSON::PRETTY_STATE_PROTOTYPE` Ref: https://github.com/ruby/json/issues/788 It is private API and will be removed. --- lib/multi_json/adapters/json_common.rb | 10 +++++++++- spec/shared/json_common_adapter.rb | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/multi_json/adapters/json_common.rb b/lib/multi_json/adapters/json_common.rb index cf65edf..5e9ab32 100644 --- a/lib/multi_json/adapters/json_common.rb +++ b/lib/multi_json/adapters/json_common.rb @@ -13,7 +13,15 @@ def load(string, options = {}) end def dump(object, options = {}) - options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty) + if options.delete(:pretty) + options.merge!({ + indent: ' ', + space: ' ', + object_nl: "\n", + array_nl: "\n", + }) + end + object.to_json(options) end end diff --git a/spec/shared/json_common_adapter.rb b/spec/shared/json_common_adapter.rb index ad18c03..d5f1f44 100644 --- a/spec/shared/json_common_adapter.rb +++ b/spec/shared/json_common_adapter.rb @@ -7,7 +7,12 @@ describe "with :pretty option set to true" do it "passes default pretty options" do object = "foo" - expect(object).to receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h) + expect(object).to receive(:to_json).with({ + indent: ' ', + space: ' ', + object_nl: "\n", + array_nl: "\n", + }) MultiJson.dump(object, pretty: true) end end From 168f101680bf0448dd1f5d1897f57068a4edebc0 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 24 Apr 2025 18:15:27 +0200 Subject: [PATCH 2/2] Time format spec no longer need to be skipped --- spec/shared/adapter.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/shared/adapter.rb b/spec/shared/adapter.rb index 27aad62..8592318 100644 --- a/spec/shared/adapter.rb +++ b/spec/shared/adapter.rb @@ -61,7 +61,6 @@ let(:json_pure){ Kernel.const_get('MultiJson::Adapters::JsonPure') rescue nil } it "dumps time in correct format" do - pending "https://github.com/flori/json/issues/573" if json_pure time = Time.at(1_355_218_745).utc dumped_json = MultiJson.dump(time)