Android Retrofit Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
10,802
if you sure the postman work, and the model same as the JSON parameter,
maybe you use the "accept-encoding: gzip" or like that in your request header.
retrofit doesn't work with gzip, remove that from the header.
Author by
user3773337
Updated on June 14, 2022Comments
-
user3773337 almost 2 years
I am using okhttp Retrofit in my Android App to make network requests. On one of the requests I get this error:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
I see a 201 response in the logs but Retrofit throws this error. Below is my code.
signup(signupParams, new Callback<Member>() { @Override public void success(Member member, Response response) { if (member != null) { UserAccount userAccount = new UserAccount(member); userAccount.save(); } @Override public void failure(RetrofitError re) { BusProvider.post(new SignupFailedEvent(re, email)); } });
signupParams value is --
{"emailAddress":"[email protected]","password":"tester123","userSource":"APH"}
I have tested this json with jsonLint and it is a valid json. And this is my Member Class which should be the response ideally.
public class Member { public String emailAddress; public String token; public long id; public String firstName; public String lastName; }
Example of the response should be something like this:
{ "emailAddress": "[email protected]", "id": 1437811, "token": "sdhshdghsdhhsdbcjhbsjdhc", "firstName": "John", "lastName": "Smith" }