Encoding a Time doesn't work correctly when json/pure is loaded
Closed this issue · 2 comments
siebertm commented
In a Rails project, do
require "yajl"
Yajl::Encoder.encode(Time.zone.now) # => "\"2011-05-18T09:45:50+02:00\"" (CORRECT)
require "json/pure"
Yajl::Encoder.encode(Time.zone.now) # => "\"2011-05-18 09:46:13 +0200\"" (WRONG)
Suprisingly, when encoding a Time outside of a Rails project:
Yajl::Encoder.encode(Time.now) # => "\"Wed May 18 09:49:34 +0200 2011\""
require "json/pure"
Yajl::Encoder.encode(Time.now) # => "\"Wed May 18 09:49:34 +0200 2011\""
Any ideas on why that happens? This keeps me from using Yajl...
ConradIrwin commented
This happens because ActiveSupport overrides the to_json method on Time objects — you should probably get in touch with the Rails project if you don't want that to happen.
brianmario commented
closing this for now, definitely a load order issue