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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Vinay Reddy

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 $"".


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;
}


My expected JSON/Body is as follows:


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


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!



--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-platform/d1a781a6-2127-460d-b381-0de296d2bef0%40googlegroups.com.