Skip to content

Commit fc39fe4

Browse files
authored
Merge pull request #293 from ekohl/drop-multi_json
Drop multi_json support
2 parents 9336df1 + bdec3ea commit fc39fe4

File tree

4 files changed

+12
-54
lines changed

4 files changed

+12
-54
lines changed

lib/puppet/util/json.rb

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,7 @@ def self.build(original_exception, data)
1616
end
1717
end
1818

19-
begin
20-
require 'multi_json'
21-
# Force backend detection before attempting to use the library
22-
# or load any other JSON libraries
23-
MultiJson.default_adapter
24-
25-
# Preserve core type monkey-patching done by the built-in JSON gem
26-
require 'json'
27-
rescue LoadError
28-
require 'json'
29-
end
19+
require 'json'
3020

3121
# Load the content from a file as JSON if
3222
# contents are in valid format. This method does not
@@ -49,46 +39,20 @@ def self.load_file(filename, options = {})
4939
# when using the built-in JSON backend, to ensure consistent behavior
5040
# whether or not MultiJson can be loaded.
5141
def self.load(string, options = {})
52-
if defined? MultiJson
53-
begin
54-
# This ensures that JrJackson and Oj will parse very large or very small
55-
# numbers as floats rather than BigDecimals, which are serialized as
56-
# strings by the built-in JSON gem and therefore can cause schema errors,
57-
# for example, when we are rendering reports to JSON using `to_pson` in
58-
# PuppetDB.
59-
case MultiJson.adapter.name
60-
when "MultiJson::Adapters::JrJackson"
61-
options[:use_bigdecimal] = false
62-
when "MultiJson::Adapters::Oj"
63-
options[:bigdecimal_load] = :float
64-
end
42+
string = string.read if string.respond_to?(:read)
6543

66-
MultiJson.load(string, options)
67-
rescue MultiJson::ParseError => e
68-
raise Puppet::Util::Json::ParseError.build(e, string)
69-
end
70-
else
71-
begin
72-
string = string.read if string.respond_to?(:read)
73-
74-
options[:symbolize_names] = true if options.delete(:symbolize_keys)
75-
::JSON.parse(string, options)
76-
rescue JSON::ParserError => e
77-
raise Puppet::Util::Json::ParseError.build(e, string)
78-
end
79-
end
44+
options[:symbolize_names] = true if options.delete(:symbolize_keys)
45+
::JSON.parse(string, options)
46+
rescue JSON::ParserError => e
47+
raise Puppet::Util::Json::ParseError.build(e, string)
8048
end
8149

8250
def self.dump(object, options = {})
83-
if defined? MultiJson
84-
MultiJson.dump(object, options)
85-
elsif options.is_a?(JSON::State)
86-
# we're being called recursively
87-
object.to_json(options)
88-
else
89-
options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
90-
object.to_json(options)
51+
# Options is a state when we're being called recursively
52+
if !options.is_a?(JSON::State) && options.delete(:pretty)
53+
options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h)
9154
end
55+
object.to_json(options)
9256
end
9357
end
9458
end

openvox.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Gem::Specification.new do |spec|
3636
spec.add_runtime_dependency('fast_gettext', '>= 2.1', '< 5')
3737
spec.add_runtime_dependency('getoptlong', '~> 0.2.0')
3838
spec.add_runtime_dependency('locale', '~> 2.1')
39-
spec.add_runtime_dependency('multi_json', '~> 1.13')
4039
spec.add_runtime_dependency('openfact', '~> 5.0')
4140
spec.add_runtime_dependency('ostruct', '>= 0.5.5', '< 0.7')
4241
spec.add_runtime_dependency('puppet-resource_api', '~> 2.0')

rakelib/benchmark.rake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'benchmark'
22
require 'tmpdir'
3-
require 'csv'
43
require 'objspace'
54

65
namespace :benchmark do
@@ -37,6 +36,8 @@ namespace :benchmark do
3736

3837
desc "Run the #{name} scenario."
3938
task :run, [*run_args] => :generate do |_, args|
39+
require 'csv'
40+
4041
report = []
4142
details = []
4243
Benchmark.benchmark(Benchmark::CAPTION, 10, Benchmark::FORMAT, "> total:", "> avg:") do |b|

spec/unit/network/formats_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,6 @@ def self.from_binary(data)
368368
expect(json.render_multiple(instances)).to eq([{"string" => "foo"}].to_json)
369369
end
370370

371-
it "should render multiple instances as a JSON array of hashes when multi_json is not present" do
372-
hide_const("MultiJson") if defined?(MultiJson)
373-
instances = [FormatsTest.new("foo")]
374-
expect(json.render_multiple(instances)).to eq([{"string" => "foo"}].to_json)
375-
end
376-
377371
it "should intern an instance from a JSON hash" do
378372
text = Puppet::Util::Json.dump({"string" => "parsed_json"})
379373
instance = json.intern(FormatsTest, text)

0 commit comments

Comments
 (0)