When Gson binding fails, it gives you a crappy exception that tells you where in the document things went sideways:
com.google.gson.JsonSyntaxException: Expected a boolean but was NUMBER at line 1 column 4728
at com.google.gson.stream.JsonReader.nextBoolean()
at com.google.gson.TypeAdapters$3.read()
at com.google.gson.TypeAdapters$3.read()
at com.google.gson.ReflectiveTypeAdapter$1.read()
at com.google.gson.ReflectiveTypeAdapter$Adapter.read()
at com.google.gson.ReflectiveTypeAdapter$Adapter.read()
at com.google.gson.ReflectiveTypeAdapter$1.read()
at com.google.gson.ReflectiveTypeAdapter$Adapter.read()
...
With Gson 2.3, you get a much nicer exception. It tells you the JSONPath to the failure. In this case, $.history[0].change_status.deletions
:
com.google.gson.JsonSyntaxException: Expected a boolean but was NUMBER at line 1 column 4728 path $.history[0].change_status.deletions
at com.google.gson.stream.JsonReader.nextBoolean()
at com.google.gson.TypeAdapters$3.read()
at com.google.gson.TypeAdapters$3.read()
at com.google.gson.ReflectiveTypeAdapter$1.read()
at com.google.gson.ReflectiveTypeAdapter$Adapter.read()
at com.google.gson.ReflectiveTypeAdapter$Adapter.read()
at com.google.gson.ReflectiveTypeAdapter$1.read()
at com.google.gson.ReflectiveTypeAdapter$Adapter.read()
...
Get Gson 2.3 from the project site or Maven Central:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>