com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 2 column 1

Searched on Google with the first line of a JAVA stack trace?

We can recommend more relevant solutions and speed up debugging when you paste your entire stack trace with the exception message. Try a sample exception.

Recommended solutions based on your search

Samebug tips

,

Your json input might be invalid. Try checking it in a validator like https://jsonlint.com

,

Your custom gson deserializer might have a bug. Try to write a unit test that checks proper deserialization of only that class by forging a json that contains a single field of that type.

Solutions on the web

via Stack Overflow by Charles
, 2 years ago
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 2 column 1
via Stack Overflow by DMR
, 2 years ago
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
via Stack Overflow by Satish Dhiman
, 2 years ago
java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 15
via co.uk by Unknown author, 1 year ago
java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 15
via GitHub by JeffreyCA
, 1 year ago
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $
via Stack Overflow by Seth Olsen
, 5 months ago
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 2 column 1
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
at com.google.gson.Gson.fromJson(Gson.java:790)
at com.google.gson.Gson.fromJson(Gson.java:756)
at com.google.gson.Gson.fromJson(Gson.java:705)
at com.atlassian.aws.ec2.EC2Utils.getUserData(EC2Utils.java:126)

Users with the same issue

2 times, 3 weeks ago
7 times, 6 months ago
Once, 6 months ago
59 times, 1 year ago
5 times, 1 year ago

Write tip

Know the solutions? Share your knowledge to help other developers to debug faster.