Skip to content

Commit 930a1ef

Browse files
apoikosjcharaoui
authored andcommitted
(PUP-11620) Avoid sending malformed PuppetDB reports with Oj
This disables the conversion of floats to BigDecimal when the Oj MultiJson adapter is being used, as is done currently with JrJackson. The original bug report is at the following URL: https://bugs.debian.org/923976 This patch has been carried for some time in the Debian Puppet package, without issue.
1 parent ac45fe2 commit 930a1ef

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/puppet/util/json.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ def self.load_file(filename, options = {})
4949
def self.load(string, options = {})
5050
if defined? MultiJson
5151
begin
52-
# This ensures that JrJackson will parse very large or very small
52+
# This ensures that JrJackson and Oj will parse very large or very small
5353
# numbers as floats rather than BigDecimals, which are serialized as
5454
# strings by the built-in JSON gem and therefore can cause schema errors,
5555
# for example, when we are rendering reports to JSON using `to_pson` in
5656
# PuppetDB.
57-
if MultiJson.adapter.name == "MultiJson::Adapters::JrJackson"
57+
case MultiJson.adapter.name
58+
when "MultiJson::Adapters::JrJackson"
5859
options[:use_bigdecimal] = false
60+
when "MultiJson::Adapters::Oj"
61+
options[:bigdecimal_load] = :float
5962
end
6063

6164
MultiJson.load(string, options)

0 commit comments

Comments
 (0)