Gson: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 2 path $

Created on 27 Feb 2019  路  1Comment  路  Source: google/gson

code is:
String userInfoStr = new Gson().fromJson("{\"name\":\"admin\"}", String.class);

Most helpful comment

This is not a bug in the library. Your JSON contains an object but you asked it to deserialize as a string. There are many questions on StackOverflow which explain this error. I would also recommend going through the Gson documentation about binding to objects which talks about how you create objects which represent JSON.

>All comments

This is not a bug in the library. Your JSON contains an object but you asked it to deserialize as a string. There are many questions on StackOverflow which explain this error. I would also recommend going through the Gson documentation about binding to objects which talks about how you create objects which represent JSON.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GoogleCodeExporter picture GoogleCodeExporter  路  19Comments

LucianWang picture LucianWang  路  42Comments

GoogleCodeExporter picture GoogleCodeExporter  路  32Comments

adiantek picture adiantek  路  23Comments

GoogleCodeExporter picture GoogleCodeExporter  路  15Comments