From 35f422ee71556e8d9a500c0d395a28e72fbc1489 Mon Sep 17 00:00:00 2001 From: Ralf Schmitz Bongiolo Date: Thu, 14 Oct 2021 18:09:02 -0400 Subject: [PATCH 1/3] Update usage of :bigdecimal_as_decimal in Rails Mode The option `:bigdecimal_as_decimal` is not available in Rails Mode (as discussed here https://github.com/ohler55/oj/issues/693), as the original JSON and Rails implementation does not have a way to "force" bigdecimal values to be encoded as numbers in json. --- pages/Modes.md | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pages/Modes.md b/pages/Modes.md index c4b997dd..eecf8a2c 100644 --- a/pages/Modes.md +++ b/pages/Modes.md @@ -95,7 +95,7 @@ information. | :array_nl | String | | | | | | x | | | :ascii_only | Boolean | x | x | 2 | 2 | x | x | | | :auto_define | Boolean | | | | | x | x | | -| :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | | +| :bigdecimal_as_decimal | Boolean | | | | | x | x | | | :bigdecimal_load | Boolean | | | | | | x | | | :compat_bigdecimal | Boolean | | | x | | | x | | | :cache_keys | Boolean | x | x | x | x | | x | | @@ -109,18 +109,18 @@ information. | :float_precision | Fixnum | x | x | | | | x | | | :hash_class | Class | | | x | x | | x | | | :ignore | Array | | | | | x | x | | -| :indent | Integer | x | x | 3 | 4 | x | x | x | +| :indent | Integer | x | x | 3 | 3 | x | x | x | | :indent_str | String | | | x | x | | x | | | :integer_range | Range | x | x | x | x | x | x | x | | :match_string | Hash | | | x | x | | x | | -| :max_nesting | Fixnum | 4 | 4 | x | | 5 | 4 | | +| :max_nesting | Fixnum | 4 | 4 | x | | 4 | 4 | | | :mode | Symbol | - | - | - | - | - | - | | | :nan | Symbol | | | | | | x | | | :nilnil | Boolean | | | | | | x | | | :object_class | Class | | | x | | | x | | | :object_nl | String | | | x | x | | x | | | :omit_nil | Boolean | x | x | x | x | x | x | | -| :quirks_mode | Boolean | | | 6 | | | x | | +| :quirks_mode | Boolean | | | 5 | | | x | | | :safe | String | | | x | | | | | | :second_precision | Fixnum | | | | | x | x | | | :space | String | | | x | x | | x | | @@ -138,22 +138,18 @@ information. 2. The :ascii_only options is an undocumented json gem option. - 3. By default the bigdecimal_as decimal is not set and the default encoding - for Rails is as a string. Setting the value to true will encode a - BigDecimal as a number which breaks compatibility. - - 4. The integer indent value in the default options will be honored by since + 3. The integer indent value in the default options will be honored by since the json gem expects a String type the indent in calls to 'to_json()', 'Oj.generate()', or 'Oj.generate_fast()' expect a String and not an integer. - 5. The max_nesting option is for the json gem and rails only. It exists for + 4. The max_nesting option is for the json gem and rails only. It exists for compatibility. For other Oj dump modes the maximum nesting is set to over 1000. If reference loops exist in the object being dumped then using the `:circular` option is a far better choice. It adds a slight overhead but detects an object that appears more than once in a dump and does not dump that object a second time. - 6. The quirks mode option is no longer supported in the most recent json + 5. The quirks mode option is no longer supported in the most recent json gem. It is supported by Oj for backward compatibility with older json gem versions. From 3b293bcc8275191b516ec8d5747ddce6003b71f2 Mon Sep 17 00:00:00 2001 From: Ralf Schmitz Bongiolo Date: Tue, 26 Oct 2021 10:32:07 -0400 Subject: [PATCH 2/3] Update docs for :bigdecimal_as_decimal in Rails Mode --- pages/Modes.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pages/Modes.md b/pages/Modes.md index eecf8a2c..b11e5ed4 100644 --- a/pages/Modes.md +++ b/pages/Modes.md @@ -95,7 +95,7 @@ information. | :array_nl | String | | | | | | x | | | :ascii_only | Boolean | x | x | 2 | 2 | x | x | | | :auto_define | Boolean | | | | | x | x | | -| :bigdecimal_as_decimal | Boolean | | | | | x | x | | +| :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | | | :bigdecimal_load | Boolean | | | | | | x | | | :compat_bigdecimal | Boolean | | | x | | | x | | | :cache_keys | Boolean | x | x | x | x | | x | | @@ -109,18 +109,18 @@ information. | :float_precision | Fixnum | x | x | | | | x | | | :hash_class | Class | | | x | x | | x | | | :ignore | Array | | | | | x | x | | -| :indent | Integer | x | x | 3 | 3 | x | x | x | +| :indent | Integer | x | x | 4 | 4 | x | x | x | | :indent_str | String | | | x | x | | x | | | :integer_range | Range | x | x | x | x | x | x | x | | :match_string | Hash | | | x | x | | x | | -| :max_nesting | Fixnum | 4 | 4 | x | | 4 | 4 | | +| :max_nesting | Fixnum | 5 | 5 | x | | 5 | 5 | | | :mode | Symbol | - | - | - | - | - | - | | | :nan | Symbol | | | | | | x | | | :nilnil | Boolean | | | | | | x | | | :object_class | Class | | | x | | | x | | | :object_nl | String | | | x | x | | x | | | :omit_nil | Boolean | x | x | x | x | x | x | | -| :quirks_mode | Boolean | | | 5 | | | x | | +| :quirks_mode | Boolean | | | 6 | | | x | | | :safe | String | | | x | | | | | | :second_precision | Fixnum | | | | | x | x | | | :space | String | | | x | x | | x | | @@ -138,18 +138,24 @@ information. 2. The :ascii_only options is an undocumented json gem option. - 3. The integer indent value in the default options will be honored by since + 3. By default the bigdecimal_as decimal is not set and the default encoding + for Rails is as a string. Setting the value to true will encode a + BigDecimal as a number which breaks compatibility. + **Beware**: after version 3.11.3 both `Oj.generate` and `JSON.generate` + will not honour this option in Rails Mode, detais on https://github.com/ohler55/oj/pull/716. + + 4. The integer indent value in the default options will be honored by since the json gem expects a String type the indent in calls to 'to_json()', 'Oj.generate()', or 'Oj.generate_fast()' expect a String and not an integer. - 4. The max_nesting option is for the json gem and rails only. It exists for + 5. The max_nesting option is for the json gem and rails only. It exists for compatibility. For other Oj dump modes the maximum nesting is set to over 1000. If reference loops exist in the object being dumped then using the `:circular` option is a far better choice. It adds a slight overhead but detects an object that appears more than once in a dump and does not dump that object a second time. - 5. The quirks mode option is no longer supported in the most recent json + 6. The quirks mode option is no longer supported in the most recent json gem. It is supported by Oj for backward compatibility with older json gem versions. From 5ad680939cb77077fbd30e9a1a9c3945076228a0 Mon Sep 17 00:00:00 2001 From: Ralf Schmitz Bongiolo Date: Wed, 27 Oct 2021 23:22:26 -0400 Subject: [PATCH 3/3] Use a more welcoming message --- pages/Modes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/Modes.md b/pages/Modes.md index b11e5ed4..8056012c 100644 --- a/pages/Modes.md +++ b/pages/Modes.md @@ -141,7 +141,7 @@ information. 3. By default the bigdecimal_as decimal is not set and the default encoding for Rails is as a string. Setting the value to true will encode a BigDecimal as a number which breaks compatibility. - **Beware**: after version 3.11.3 both `Oj.generate` and `JSON.generate` + Note: after version 3.11.3 both `Oj.generate` and `JSON.generate` will not honour this option in Rails Mode, detais on https://github.com/ohler55/oj/pull/716. 4. The integer indent value in the default options will be honored by since