discomarathon / google-gson

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

JsonParseExceptions (or specialized sub-classes) should provide more specific info #160

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
JsonParseException contains only the usual message and cause. What I am 
specifically looking for is separate properties outlining details of what 
went wrong when parsing a value. Specifically, the field name (if it was a 
field), and target and actual data based on what went wrong. If the type 
was wrong, show target and actual type (string vs. boolean vs. BigDecimal, 
etc.). Perhaps a specific format is required, then I would want the text 
position where the actual value diverges.

The JPE message do typically contain this information. The problem is that 
they often contain information appropriate to a consumer over HTTP. Most 
often it's the name of the target Java class. With the bits of information 
provided separately on the exception, I could construct a more appropriate 
error message.

So, e.g., instead of:

The JsonDeserializer BigDecimalTypeAdapter failed to deserialized json 
object "abcde" given the type class java.math.BigDecimal

I would send to the client:

For field X: expected a decimal number and instead got a string

Which would be more friendly to non-java consumers of my json

Original issue reported on code.google.com by estebis...@gmail.com on 25 Sep 2009 at 3:08

GoogleCodeExporter commented 9 years ago
I agree with the goal but it is not as straightforward in the current design. 
At the 
point where the exception is thrown, we are not in the context of the parent, 
we are 
in the context of the object being deserialized. However, we will see what can 
be done 
about this in a future release.

Original comment by inder123 on 25 Sep 2009 at 5:31

GoogleCodeExporter commented 9 years ago

Original comment by inder123 on 25 Sep 2009 at 5:34

GoogleCodeExporter commented 9 years ago

Original comment by inder123 on 1 Nov 2010 at 11:24

GoogleCodeExporter commented 9 years ago
Let's finally get this done!

Original comment by limpbizkit on 29 Dec 2011 at 6:03