Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at com.google.gson.Gson.fromJson(Gson.java:724)
at com.google.gson.Gson.fromJson(Gson.java:696)
at JsonToGsonExample.main(JsonToGsonExample.java:52)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
JsonSyntaxException is when you are trying to parse a JSON String and it is not well formatted. BEGIN_OBJECT is the start of a JSON object and it should be open curly braces {, which is surely missing
Fix:
- Add the missing { for the JSON String
- If the error is not on line 1 column 1, just follow the line and column to reach to the location within your JSON and add the missing curly brace.
- Make sure your JSON String is valid. You may make use of Online JSON Validators (careful not to have sensitive data)
Before fix: "name":"ABC", "age":22}
Ater fix: { "name":"ABC", "age":22}
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!