Tag Archives: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

[Solved] java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

This error is caused by the inconsistency between the incoming string and the class of the object when gson parses the JSON string into an object

Solution:

Either modify the background method and change the structure type of the return value to be consistent with the specified class;

Either modify the class structure of the foreground transformation. In short, the data to be parsed must correspond to the structure of the transformed instance