java - Gson throwing EXPECTED_ARRAY but found String Exception -


i using gson retrofit parse json response getting above mention exception. have tried searching on net , figuring out myself haven't got success till now

here json response:

{     "success": "true",     "message": "",     "data": [{         "id": "56b5d1408b8d9",         "name": "john",         "age":"28",         "place": "central city"     }] }  pojo class  public class datum {  @serializedname("id") @expose private string id; @serializedname("name") @expose private string name; @serializedname("age") @expose private string age; @serializedname("place") @expose private string place;  /** *  * @return * id */ public string getid() { return id; }  /** *  * @param id * id */ public void setid(string id) { this.id = id; }  /** *  * @return * name */ public string getname() { return name; }  /** *  * @param name * name */ public void setname(string name) { this.name = name; }  /** *  * @return * age */ public string getage() { return age; }  /** *  * @param age * age */ public void setage(string age) { this.age = age; }  /** *  * @return * place */ public string getplace() { return place; }  /** *  * @param place * place */ public void setplace(string place) { this.place = place; }  } 

parent class package com.example;

import java.util.arraylist; import java.util.list; import javax.annotation.generated; import com.google.gson.annotations.expose; import com.google.gson.annotations.serializedname;  @generated("org.jsonschema2pojo") public class usermodel {  @serializedname("success") @expose private string success; @serializedname("message") @expose private string message; @serializedname("data") @expose private list<datum> data = new arraylist<datum>();  /** *  * @return * success */ public string getsuccess() { return success; }  /** *  * @param success * success */ public void setsuccess(string success) { this.success = success; }  /** *  * @return * message */ public string getmessage() { return message; }  /** *  * @param message * message */ public void setmessage(string message) { this.message = message; }  /** *  * @return * data */ public list<datum> getdata() { return data; }  /** *  * @param data * data */ public void setdata(list<datum> data) { this.data = data; }  }    

here code parse it

private void getuserdetail(){

    call<usermodel> usermodelcall = util.getendpointservice().fetchuser(sessionid, startno);     usermodelcall.enqueue(new callback<usermodel>() {         @override         public void onresponse(response<usermodel> response) {             int rescode = response.code();             log.i(tag_debug, "response code " + rescode);             if (rescode == 200) {                 usermodel usermodel = response.body();                 log.i(tag_debug, usermodel.getsuccess());                  if (usermodel.getsuccess().equals(stringconstants.true)) {                     retrievedownloadedprofile(usermodel);                 }             }         }          @override         public void onfailure(throwable t) {             clog.e(tag_debug, "exception in getuserdetail " + t);             t.printstacktrace();         }     });  } 

gson start working root, you'll need parent matches response like:

class myresponse {     public list<datum> data; } 

your datum class looks matches items inside data array in response


Comments