Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Retrofit Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

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"
}
like image 599
user3773337 Avatar asked Oct 05 '15 23:10

user3773337


1 Answers

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.

like image 151
Rasoul Miri Avatar answered Sep 18 '22 02:09

Rasoul Miri