Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork262
-
Please place notes about dealing with Rails and ActiveSupport in this discussion topic. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 2 comments 2 replies
-
What is the main difference between |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
However, But if you set Basically, if you don't want to set |
BetaWas this translation helpful?Give feedback.
All reactions
-
The interaction between Rails and the JSON gem can be somewhat unpredictable. Oj does it's best to reproduce that. As pointed out |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hey, everyone, this write-up mostly relates to a caveat when using TL/DR: In Extended details below: My understanding is that with Here's a demonstration with these Oj settings: # Oj version 3.10.0#JSON.dumpJSON.dump(Time.now.utc)=>"2022-01-11 12:17:36 UTC"# ActiveSupport::JSON.encodeActiveSupport::JSON.encode(Time.now.utc)=>"2022-01-11T12:17:36.614Z"# Oj.dump#0: rails.c:1468:Oj:}: dump Time#0: rails.c:517:Oj:>: as_json Time#0: rails.c:527:Oj:<: as_json Time#0: rails.c:1468:Oj:}: dump String#0: rails.c:1479:Oj:{: dump String#0: rails.c:1479:Oj:{: dump TimeOj.dump(Time.now.utc)=>"2022-01-11T12:17:36.614Z" Notice above the Now, if we run the same code but add # Oj version 3.10.0#JSON.dump#0:dump_compat.c:940:Oj:}: dump Time#0:dump_compat.c:965:Oj:{: dump TimeJSON.dump(Time.now.utc)=>"2022-01-11 12:27:17 UTC"# ActiveSupport::JSON.encode#0: rails.c:1468:Oj:}: dump Time#0: rails.c:1479:Oj:{: dump TimeActiveSupport::JSON.encode(Time.now.utc)=>"2022-01-11T12:27:17.051Z"# Oj.dump#0: rails.c:1468:Oj:}: dump Time#0: rails.c:1479:Oj:{: dump TimeOj.dump(Time.now.utc)=>"2022-01-11T12:27:17.051Z" Both The bug in # Oj version 3.10.0# JSON.dump#0:dump_compat.c:940:Oj:}: dump Hash#0:dump_compat.c:940:Oj:}: dump Time#0:dump_compat.c:123:Oj:>: to_json Time#0: rails.c:1468:Oj:}: dump Time#0: rails.c:1479:Oj:{: dump Time#0:dump_compat.c:131:Oj:<: to_json Time#0:dump_compat.c:965:Oj:{: dump Time#0:dump_compat.c:965:Oj:{: dump HashJSON.dump({created_at:Time.now.utc})=>{"created_at":"2022-01-11T12:27:16.966Z"} As you can see in the trace, This was fixed in # Oj version 3.10.1# JSON.dump#0:dump_compat.c:941:Oj:}: dump Hash#0:dump_compat.c:941:Oj:}: dump Time#0:dump_compat.c:123:Oj:>: to_json Time#0:dump_compat.c:131:Oj:<: to_json Time#0:dump_compat.c:966:Oj:{: dump Time#0:dump_compat.c:966:Oj:{: dump HashJSON.dump({created_at:Time.now.utc})=>{"created_at":"2022-01-11 12:34:36 UTC"}
Because Oj has to mimic the JSON standard library gem time format and, separately, mimic the ActiveSupport time format (both of which Oj has no control over, it just needs to adapt) we might write a test that catches whenever one the formats change. |
BetaWas this translation helpful?Give feedback.