You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The message of exceptions thrown by JsonReader usually contains location information including the current path. This is really helpful to locate the error in the input JSON.
Example: java.lang.IllegalStateException: Expected an int but was BOOLEAN at line 7 column 10 path $.x.y
Now JsonReader.nextInt(), .nextLong(), .nextDouble() may throw exceptions that contain no such location information. The exception is thrown in the lines double asDouble = Double.parseDouble(peekedString); // don't catch this NumberFormatException.
How to provoke that specific exception:
Model: public class Model { int x; }
and then call new GsonBuilder().create().fromJson("{ x: ''}", Model.class}
The exception message will be: java.lang.NumberFormatException: empty String, containg no location information.
The exception itself was thrown by Double and JsonReader just passed it along.
Imho JsonReader should catch the exception from Double.parseDouble and add location information to a rethrown copy.
The text was updated successfully, but these errors were encountered:
The message of exceptions thrown by
JsonReader
usually contains location information including the current path. This is really helpful to locate the error in the input JSON.Example:
java.lang.IllegalStateException: Expected an int but was BOOLEAN at line 7 column 10 path $.x.y
Now
JsonReader.nextInt(), .nextLong(), .nextDouble()
may throw exceptions that contain no such location information. The exception is thrown in the linesdouble asDouble = Double.parseDouble(peekedString); // don't catch this NumberFormatException.
How to provoke that specific exception:
Model:
public class Model { int x; }
and then call
new GsonBuilder().create().fromJson("{ x: ''}", Model.class}
The exception message will be:
java.lang.NumberFormatException: empty String
, containg no location information.The exception itself was thrown by
Double
andJsonReader
just passed it along.Imho JsonReader should catch the exception from
Double.parseDouble
and add location information to a rethrown copy.The text was updated successfully, but these errors were encountered: