IvanConrad / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

date (de)serialization #410

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Gson gson = new Gson();
Date tmp = new Date();
Date tmp2 = gson.fromJson(gson.toJson(tmp), Date.class);
assertEquals("Timestamp is correct", tmp, tmp2);

What is the expected output? What do you see instead?

Expect that the two dates are equal and the assertion doesn't fail.

See:

junit.framework.AssertionFailedError: Timestamp is correct expected:<Thu Feb 16 
15:25:29 EST 2012> but was:<Thu Feb 16 15:25:29 EST 2012>

the fasttime values are different in the debugger

What version of the product are you using? On what operating system?

gson 2.1

2.6.18-194.3.1.el5xen x86_64 GNU/Linux

Please provide any additional information below.

the fasttime values are different in the debugger

Original issue reported on code.google.com by avi.hers...@gmail.com on 16 Feb 2012 at 9:17

GoogleCodeExporter commented 9 years ago
It's likely a problem with millisecond precision. Work around this by 
registering your own type adapter for Date.

Original comment by limpbizkit on 17 Feb 2012 at 4:33

GoogleCodeExporter commented 9 years ago
Use the GsonBuilder to call setDateFormat if you would like to specify that  
you would like to preserve the milliseconds as well.

https://gist.github.com/2495636

Original comment by l...@leviwilson.com on 26 Apr 2012 at 3:48