Pass JSON Array in Retrofit 2.1 -


how can pass jsonarray in api call using retrofit 2.1 json

{ "address":[     {         "addresstype":"home",         "addressline1":"m12/150, vidhyanagar flates",         "addressline2": "op. himmatlal park, satelite",         "city":"ahmedabad",         "state":"gujarat",         "zipcode":"380015",         "country_id":"109",         "latitude":"23.13213",         "longitude":"72.313213",         "isdefault":"0"     } ] 

}

response

{   "status": 1,   "message": "address stored successfully.",   "result":  [ {   "id": 16,   "user_id": 33,   "addresstype": "home",   "addressline1": "m12/150, vidhyanagar flates",   "addressline2": "op. himmatlal park, satelite",   "city": "ahmedabad",   "state": "gujarat",   "zipcode": "380015",   "country_id": 109,   "latitude": "23.13213",   "longitude": "72.313213",   "isdefault": 0,   "created_at": "2016-09-22 06:37:43",   "updated_at": "2016-09-22 06:37:43",   "deleted_at": null } 

}

pojo class 1.address.java

public class address {  @serializedname("status") @expose private int status; @serializedname("message") @expose private string message; @serializedname("result") @expose private arraylist<addressdetail> addressdetail = new arraylist<addressdetail>();  /**  *  * @return  * status  */ public int getstatus() {     return status; }  /**  *  * @param status  * status  */ public void setstatus(int status) {     this.status = status; }  /**  *  * @return  * message  */ public string getmessage() {     return message; }  /**  *  * @param message  * message  */ public void setmessage(string message) {     this.message = message; }  /**  *  * @return  * addressdetail  */ public list<addressdetail> getaddressdetail() {     return addressdetail; }  /**  *  * @param addressdetail  * addressdetail  */ public void setaddressdetail(arraylist<addressdetail> addressdetail) {     this.addressdetail = addressdetail; } 

}

2.addressdetail.java

public class addressdetail {      @serializedname("id")     @expose     private int id;     @serializedname("user_id")     @expose     private int userid;     @serializedname("addresstype")     @expose     private string addresstype;     @serializedname("addressline1")     @expose     private string addressline1;     @serializedname("addressline2")     @expose     private string addressline2;     @serializedname("city")     @expose     private string city;     @serializedname("state")     @expose     private string state;     @serializedname("zipcode")     @expose     private string zipcode;     @serializedname("country_id")     @expose     private int countryid;     @serializedname("latitude")     @expose     private string latitude;     @serializedname("longitude")     @expose     private string longitude;     @serializedname("isdefault")     @expose     private int isdefault;     @serializedname("created_at")     @expose     private string createdat;     @serializedname("updated_at")     @expose     private string updatedat;     @serializedname("deleted_at")     @expose     private object deletedat;      /**      *      * @return      * id      */     public int getid() {             return id;     }      /**      *      * @param id      * id      */     public void setid(int id) {             this.id = id;     }      /**      *      * @return      * userid      */     public int getuserid() {             return userid;     }      /**      *      * @param userid      * user_id      */     public void setuserid(int userid) {             this.userid = userid;     }      /**      *      * @return      * addresstype      */     public string getaddresstype() {             return addresstype;     }      /**      *      * @param addresstype      * addresstype      */     public void setaddresstype(string addresstype) {             this.addresstype = addresstype;     }      /**      *      * @return      * addressline1      */     public string getaddressline1() {             return addressline1;     }      /**      *      * @param addressline1      * addressline1      */     public void setaddressline1(string addressline1) {             this.addressline1 = addressline1;     }      /**      *      * @return      * addressline2      */     public string getaddressline2() {             return addressline2;     }      /**      *      * @param addressline2      * addressline2      */     public void setaddressline2(string addressline2) {             this.addressline2 = addressline2;     }      /**      *      * @return      * city      */     public string getcity() {             return city;     }      /**      *      * @param city      * city      */     public void setcity(string city) {             this.city = city;     }      /**      *      * @return      * state      */     public string getstate() {             return state;     }      /**      *      * @param state      * state      */     public void setstate(string state) {             this.state = state;     }      /**      *      * @return      * zipcode      */     public string getzipcode() {             return zipcode;     }      /**      *      * @param zipcode      * zipcode      */     public void setzipcode(string zipcode) {             this.zipcode = zipcode;     }      /**      *      * @return      * countryid      */     public int getcountryid() {             return countryid;     }      /**      *      * @param countryid      * country_id      */     public void setcountryid(int countryid) {             this.countryid = countryid;     }      /**      *      * @return      * latitude      */     public string getlatitude() {             return latitude;     }      /**      *      * @param latitude      * latitude      */     public void setlatitude(string latitude) {             this.latitude = latitude;     }      /**      *      * @return      * longitude      */     public string getlongitude() {             return longitude;     }      /**      *      * @param longitude      * longitude      */     public void setlongitude(string longitude) {             this.longitude = longitude;     }      /**      *      * @return      * isdefault      */     public int getisdefault() {             return isdefault;     }      /**      *      * @param isdefault      * isdefault      */     public void setisdefault(int isdefault) {             this.isdefault = isdefault;     }      /**      *      * @return      * createdat      */     public string getcreatedat() {             return createdat;     }      /**      *      * @param createdat      * created_at      */     public void setcreatedat(string createdat) {             this.createdat = createdat;     }      /**      *      * @return      * updatedat      */     public string getupdatedat() {             return updatedat;     }      /**      *      * @param updatedat      * updated_at      */     public void setupdatedat(string updatedat) {             this.updatedat = updatedat;     }      /**      *      * @return      * deletedat      */     public object getdeletedat() {             return deletedat;     }      /**      *      * @param deletedat      * deleted_at      */     public void setdeletedat(object deletedat) {             this.deletedat = deletedat;     } 

}

how can call api using retrofit 2.1.don't know how pass jsonarray. call api like

@post("address") call<address> addresscall(@body map<string, string> map); 

why want pass map<string,string> ? it's better if send object reprensent data. somethings addressedetails , null properties can configure parser.

i think become :

@post("address") call<address> addresscall(@body list<addressdetail> newaddresses); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -