Oj: Compat mode behavior change

Created on 26 Jan 2021  路  8Comments  路  Source: ohler55/oj

Steps to reproduce

$ irb
> require 'oj'
> Oj.default_options = { mode: :compat }
> Oj.load('3.14159265358979323846')
> Oj.load('3.141592653589793')

Expected behavior

oj 3.10.18 behavior

> Oj.load('3.14159265358979323846')
=> 0.314159265358979323846e1
> Oj.load('3.141592653589793')
=> 3.141592653589793

Actual behavior

after oj 3.11.0

> Oj.load('3.14159265358979323846')
=> 3.141592653589793
> Oj.load('3.141592653589793')
=> 3.141592653589793

https://github.com/ohler55/oj/blob/2e83d4dd46f0cf40ce1209b62629f87c9389673d/ext/oj/oj.c#L596-L600
compat_bigdec is expect boolean, but assign BigLoad. Is it correct?

All 8 comments

I do believe you have found a bug. I'll get that fixed tomorrow. Good catch. Basically any value would be treated as true.

Please try the bug/decimal-class branch.

Thanks.

bug/decimal-class branch behavior is below.

> Oj.load('3.14159265358979323846')
=> 3.141592653589793
> Oj.load('3.141592653589793')
=> 3.141592653589793

Did AutoDec become unusable compat mode?

Yes. compat mimics the JSON which does not have the :bigdecimal_load that Oj has. The JSON gem alternative is :decimal_class which can be either Float or BigDecimal. It is not a documented feature of the JSON gem but it does exist. To use the Oj :bigdecimal_load option the custom mode is best.

Thank you for your advice. I change to use custom mode.

bug/decimal-class branch commit looks good to me 馃憤

Thank you. I will release today.

Released. 39

Thanks for the quick release.

Was this page helpful?
0 / 5 - 0 ratings