-
-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
to_json() and bigdecimal_as_decimal behavior different with and without argument #659
Comments
When To verify there is a bug in Oj, compare to how the JSON gem works. |
Were you able to find a case where Oj in compat mode differed in behaviour from the JSON gem? If not can this be closed? |
@ohler55: Apologies for the delay in following up, but thanks for the speedy reply! Since this difference in behavior is specific to Oj's
I just wasn't sure how passing arguments to Although, if Oj is trying to emulate what the JSON gem does, and the JSON gem doesn't support the |
I'd love to claim that it is the intended behaviour and in some sense it is but you are right that it is due to attempting to cover all the compatibility modes between the JSON gem and Rails. Checkout issue #651 . It is a rabbit hole so deep it is some number of circles of hell. I'm sure there is some additional flag that could be kept and passed down for all calls but I can't easily fix the behaviour without breaking something else. It comes down to I think the best approach to solving the issue is just don't set Oj's |
Chiming in as we're blocked from upgrading from 3.11.3 to 3.11.4+ due to it breaking our API tests. We're using Rails, Blueprinter and Oj (similar to this ticket #656) so can't easily change how the Oj is being called. Our API tests are failing on 3.11.4+ due to numbers being returned as quoted strings (e.g. We're using |
Rails 6.1.7.3 I'd really appreciate some guidance on how to bump Oj from 3.11.3 to 3.11.4+ too as I'm struggling to get it to work. When I update the gem to 3.11.4 I get the following classes of test failures: Dates formatted differently:
Hashes not getting turned into hashes again:
Extra hash keys
Numbers as strings
The config we were using for 3.11.3 was simply: Oj.optimize_rails I've tried all manner of variations of What config do I need to do to make Oj 3.11.4 work the same as 3.11.3? I'd really love to be able to fix our app to work in the same way Rails does, but though there are only 22 test failures there will unfortunately likely be many more places that aren't tested that will break so I'm kinda stuck persisting the behaviour of 3.11.3. |
That is quite a few issues and I'm not sure I understand how each is encountered so let's look at one at a time but first let's deal with the version issues. You are using an unsupported version of Ruby and Rails. The Oj version is more than a year old. Is there any way you can move to more recent versions of any or all of those? |
We plan on moving upgrading:
Oj we're trying to upgrade right now, that's what this post is about :) The strange thing is, we had 100% of tests passing and went to 22 tests failing (see the examples above) and the only change was going from Oj 3.11.3 to 3.11.4 so what changed in 3.11.4 that could cause these things to break? |
The changelog shows a fix for conflict between Rails and the JSON gem. If I had to guess it would be related to that where JSON.generate produces something different than to_json. If you can tolerate the wait I'd suggest waiting until you update Ruby and Rails and then we can look at how or if Oj produces different results. I'd prefer not to branch off old releases and instead stay with the current. I don't have the bandwidth to track more than one release branch. |
This seems like it might be a bug, but I know the JSON compatibility/mimicking gets complicated, so let me know if this is expected behavior.
When using the
Oj.optimize_rails
mode inside a Rails app, the basic issue I'm seeing is thatto_json
seems to behave differently if arguments are passed into theto_json()
call or not. Specifically, the presence of an argument toto_json
(eg,to_json({})
seems to break the behavior of thebigdecimal_as_decimal
option set viaOj.default_options
. In quickly testing some other options set viaOj.default_options
, those other options do not seem to be affected, so it's possible this only affects thebigdecimal_as_decimal
option (but not entirely sure).Here's a script that demonstrates the issue (the comments show the output I'm observing and what might be expected instead):
Thank you!
The text was updated successfully, but these errors were encountered: