FranzGames / google-gson

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

Gson fails to deserialize long value with .0 decimal when in custom deserializer #461

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When attempting to deserialize object with long field from JSON containing 
value such as 1342911054.0, using custom deserializer, Gson throws a 
NumberFormatException. If not defining any deserializer for the object, works 
fine but does not allow any custom handling of fields.
See code for detail in reduced test case. Code also contains workaround for 
this issue. However, I do not know if it has any unwanted side effects.

What is the expected output? What do you see instead?
Gson should verify that double value equals long value then return it. Gson 
instead throws NumberFormatException. NFE is also displaying substring of value 
(missing first 3 chars) instead of actual value.

What version of the product are you using? On what operating system?
Gson 2.2.2 on JDK 7u5 x86 on Windows 7 SP1 x64

Original issue reported on code.google.com by alek...@sovietnation.net on 21 Jul 2012 at 8:25

Attachments:

GoogleCodeExporter commented 9 years ago
And now I realize that the reason it fails is because a JsonTreeReader is being 
used, instead of a JsonReader. JsonTreeReader's nextLong method is more strict 
than JsonReader's method.

Original comment by alek...@sovietnation.net on 22 Jul 2012 at 12:49

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 2 Sep 2012 at 9:33