@@ -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
9458end
0 commit comments