Post the data to server using retrofit in android -


i have tried post data server using retrofit. tried create serialized request post data. if request

{ "firstname":"test", "lastname":"test", "emailaddress":"test@test.com", "password":"test", "devicetoken":"", "pushtoken":"", "devicetype":"test", "smssubscribe":"1", "emailsubscribe":"1", "termscondition":"1", } 

then created serialized class

public class registerrequest {  @serializedname("devicetoken") public string devicetoken;  @serializedname("pushtoken") public string pushtoken;  @serializedname("appversion") public string appversion;  @serializedname("deviceplatform") public string deviceplatform;  @serializedname("devicetype") public string devicetype;  @serializedname("firstname") public string firstname;  @serializedname("lastname") public string lastname;  @serializedname("emailaddress") public string email;  @serializedname("password") public string password;  @serializedname("mobilecountrycode") public string mobilecountrycode;  @serializedname("mobilenumber") public string mobilenumber;  @serializedname("smssubscribe") public string smssubscribe;  @serializedname("emailsubscribe") public string emailsubscribe;  @serializedname("termscondition") public string termscondition;  @serializedname("deviceinformation") public string deviceinformation; 

}

@headers({token, content_type_json, language_code, app_version}) @post("api/registerstep1") call<commonresponse> register(@body registerrequest registerrequest); 

then post data

 final registerrequest registerrequest = new registerrequest();     registerrequest.firstname = givenname;     registerrequest.lastname = familyname;     registerrequest.email = email;     registerrequest.password = password;     registerrequest.devicetoken = repository.getdeviceid();     registerrequest.pushtoken = "";     registerrequest.devicetype = repository.device_type;     registerrequest.appversion = repository.app_version;     registerrequest.deviceplatform = repository.device_platform;     registerrequest.mobilenumber = mobileno;     registerrequest.mobilecountrycode = mselectedcountrycode;     registerrequest.deviceinformation = repository.device_info;   repository.apiservice().register(registerrequest).enqueue(new basecallback<commonresponse>() {         @override         public void onsuccess(commonresponse body) {             super.onsuccess(body); 

but want know how create serialized class post below format data server

{ "reg_company": {      "referencecode":"referencecode",      "companytype":"1",     "companyname": "test",     "companyemailaddress": "test@test.com",     "companytier": "1",     "contactnumber": "99999",     "oilchangepermonth": "1",     "oilchangepercentage": "1",     "shellhelixqty": "1",     "remarks": "1" },  "reg_companyaddress": {         "addresstype":"1",         "address1":"address1",         "address2":"address2",          "streetname":"streetname",          "companycity":"companycity",          "companystate":"companystate",          "postalcode":"postalcode",          "longitude":"longitude",           "latitude":"latitude"  },  "reg_companyservice": [         {"serviceid":1         },{"serviceid":2}]         ,  "reg_companyhours": [         {"weekday":1,         "isopen":1,         "starttime":1,         "closetime":1         }, {"weekday":1,         "isopen":1,         "starttime":1,         "closetime":1         }],  "reg_member": {      "userid":"userid",      "userpassword":"userpassword",     "salutation": "1",     "firstname": "firstname",     "lastname": "lastname",     "mobilenumber": "mobilenumber",     "emailaddress": "emailaddress",     "gender": "1",     "contactpreference": "1",     "registrationtype": "1",     "registrationmode": "1" } } 

you can use below code serialized model class.

@serializedname("reg_companyaddress") public companyaddress address = new companyaddress();  @serializedname("reg_companyservice") public list<service> services = new arraylist<>();    public static class service {      @serializedname("serviceid")     public integer serviceid;  }      public static class companyaddress {      @serializedname("addresstype")     public string addresstype;      @serializedname("address1")     public string address1;      .......     code       } 

like ca create other fields


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -