Skip to content
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

inconsistency with Time serialization #29

Closed
colinsurprenant opened this issue Jun 11, 2014 · 4 comments
Closed

inconsistency with Time serialization #29

colinsurprenant opened this issue Jun 11, 2014 · 4 comments

Comments

@colinsurprenant
Copy link
Collaborator

Time object will be handled by to_s at https://github.com/guyboertje/jrjackson/blob/master/lib/jrjackson/jrjackson.rb#L45

JrJackson::Json.dump(Time.now)
=> "2014-06-10 23:19:37 -0400"

Time object will be handled by Jackson as a Java::JavaUtil::Date

JrJackson::Json.dump([Time.now])
=> "[\"2014-06-10 23:24:11 EDT\"]"

Time object will be handled by Jackson as a Java::JavaUtil::Date

JrJackson::Raw.generate(Time.now)
=> "\"2014-06-10 23:25:04 EDT\""

Wouldn't it be better to also add Time as a shortcut to JrJackson::Raw.generate at https://github.com/guyboertje/jrjackson/blob/master/lib/jrjackson/jrjackson.rb#L36 ?

@guyboertje
Copy link
Owner

hmmm - need to check. But there is are many of datetime like objects in the ruby/rails eco system.
Time, DateTime, Date and then the Rails wrappers with time zone.

Also I wonder whether Date or DateTime is consistent in and out of an array.

@colinsurprenant
Copy link
Collaborator Author

JrJackson::Json.dump(Time.now.to_date)
=> "2014-06-11"
JrJackson::Json.dump([Time.now.to_date])
=> "[\"2014-06-11 00:00:00 EDT\"]"
JrJackson::Json.dump(Time.now.to_datetime)
=> "2014-06-11T09:12:16-04:00"
JrJackson::Json.dump([Time.now.to_datetime])
=> "[\"2014-06-11 09:12:22 EDT\"]"

also, as noted, JRuby coerces Time object to Java::JavaUtil::Date

irb(main):033:0> Time.now.to_java
=> #<Java::JavaUtil::Date:0x1042db3e>

but Date and DateTime to OrgJodaTime::DateTime

Time.now.to_datetime.to_java
=> #<DateTime:0x2012e4d @dt=#<Java::OrgJodaTime::DateTime:0x1b86c242>, @sub_millis=0, @of=(-1/6), @sg=2299161>
Time.now.to_date.to_java
=> #<Date:0x2e80f606 @dt=#<Java::OrgJodaTime::DateTime:0x14981bc4>, @sub_millis=0, @of=0, @sg=#<Date::Infinity:0x520a06c6 @d=-1>>

So it looks like Java::JavaUtil::Date and Java::OrgJodaTime::DateTime are also correctly handled by Jackson but JrJackson::Json.dump will apply to_s on Time, Date and DateTime.

@PetrKaleta
Copy link

Any update on this issue? Please also have a look on my comments in this issue #12 Its not just a "format" issue, but serialisation of UTC time works wrong

@guyboertje
Copy link
Owner

I have added some comments to #12 and copied them to a new wiki page. Ruby Time serialisation. @PetrKaleta, I believe that the additions by @colinsurprenant implemented in release 0.2.8 fixes this. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants