I am getting exception (java.lang.IllegalStateException: Expected xxxx but was yyyy) when trying to get a response from an https call [duplicate]

32 views
Skip to first unread message

JayHawk

unread,
Aug 15, 2019, 4:07:13 PM8/15/19
to google-gson

I am trying to get a callback from an http request. However, I can't seem to hit the breakpoint placed at "/* Do something */" in my code below.


After debugging I realized deep in my code I am getting the following exception "Excpetion "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $"".


My expected JSON/Body is as follows:


[
 {
  "id": "12345678",
  "guidNumber": 7893797597987594,
  "languageId": "ja",
  "detectedLanguage": 
     {
      "languageId": null,
      "race": 8.7
     },
    "resultCode": "Success"
   }
  ]


Function invoking the Http Call:


public void postTMRequest(String lId, RequestBody bodyFinal) {

         IHttpResponseCallback<TBody> callback =
            createTMResponseCallback(ApiName.POST_PARSING);

         mHttpCallExecutor.execute(
            ServiceType.TPA,
            ApiName.POST_PARSING,
            new HttpCallExecutor.IEndpointGetter<TBody>() {
                @Override
                public Call<TranslatorBody> getEndpoint() {
                    return TpaServiceProvider.getTpaService()
                                             .parse(lId,bodyFinal);
                }
            },
            callback,
            CancellationToken.NONE);
}


Callback function:


private IHttpResponseCallback<TBody>
createTMResponseCallback(final String apiName) {
    return new IHttpResponseCallback<TBody>() {
        @Override
        public void onResponse(Response<TBody> response) {
            /* Do something */
        }
    };
}


TBody Class:


public class TBody {

@SerializedName("content")
@Expose
public List<TMessage> content;
}


TMessage Class:


public class TMessage {
@SerializedName("id")
@Expose
public String id;

@SerializedName("guidNumber")
@Expose
public long guidNumber;

@SerializedName("languageId")
@Expose
public String languageId;

@SerializedName("detectedLanguage")
@Expose
public DetectedLanguage detectedLanguage;

@SerializedName("resultCode")
@Expose
public String resultCode;
}


Detected Class:


public class DetectedLanguage {
@SerializedName("languageId")
@Expose
public String languageId;

@SerializedName("race")
@Expose
public float race;
}


I am assuming I am passing the body of the Response callback is incorrect. However, I am not sure why its wrong.

Would greatly appreciate any tips or pointers as to what is wrong here.


Thanks!



Reply all
Reply to author
Forward
0 new messages