Kumen / google-gson

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

inconsistency LazilyParsedNumber vs. JsonReader.nextInt() #462

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
See attached JUnit test.

What is the expected output?
I expect Gson fromJson(JsonElement json, Class<T> classOfT) to behave like Gson 
fromJson(String json, Class<T> classOfT) when I use the same json string input 
but converted the first one with JsonParser .parse(String json). 

What do you see instead?
Instead I got that exception:

com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: For input 
string: "1.0"
    at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:230)
    at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:220)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
    at com.google.gson.Gson.fromJson(Gson.java:755)
    at com.google.gson.Gson.fromJson(Gson.java:819)
    at com.google.gson.Gson.fromJson(Gson.java:792)
    at GsonTest.testWithJsonString(GsonTest.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NumberFormatException: For input string: "1.0"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:458)
    at java.math.BigInteger.<init>(BigInteger.java:316)
    at java.math.BigInteger.<init>(BigInteger.java:451)
    at com.google.gson.internal.LazilyParsedNumber.intValue(LazilyParsedNumber.java:41)
    at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:255)
    at com.google.gson.internal.bind.JsonTreeReader.nextInt(JsonTreeReader.java:197)
    at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:228)
    ... 30 more

What version of the product are you using? On what operating system?
Could be reproduced with 2.1 and 2.2.2

Original issue reported on code.google.com by s.groeb...@googlemail.com on 26 Jul 2012 at 3:35

Attachments:

GoogleCodeExporter commented 9 years ago
sorry I mixed up the method names in the test. here is the corrected one.

Original comment by s.groeb...@googlemail.com on 26 Jul 2012 at 3:40

Attachments:

GoogleCodeExporter commented 9 years ago
This is a bug!

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

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago
Issue 461 has been merged into this issue.

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

GoogleCodeExporter commented 9 years ago

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