i am new to retrofit and getting problem in sending my data to server
i am trying to hit registration api from my mobile application with raw body which is as follows :-
{
"fullName": "test user",
"gender": "male",
"age": 25,
"email": "[email protected]",
"phoneNumber": 7696016749,
"password": "Admin123#",
"loc": [30.5234234, 75.4645646545] ,
"deviceId": "adssads90ads89afyh89sayfs89afs90afys890afsa",
"deviceType": "ios"
}
if i hit this in post man it's working fine,but with code it's not here i am posting some of my code please review and let me know where i am doing wrong.
POJO of the response :-
public class RequestModel {
@SerializedName("fullName")
@Expose
private String fullName;
@SerializedName("gender")
@Expose
private String gender;
@SerializedName("age")
@Expose
private Integer age;
@SerializedName("email")
@Expose
private String email;
@SerializedName("phoneNumber")
@Expose
private Integer phoneNumber;
@SerializedName("password")
@Expose
private String password;
@SerializedName("loc")
@Expose
private List<Double> loc = null;
@SerializedName("deviceId")
@Expose
private String deviceId;
@SerializedName("deviceType")
@Expose
private String deviceType;
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(Integer phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<Double> getLoc() {
return loc;
}
public void setLoc(List<Double> loc) {
this.loc = loc;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
}
Service class :-
public interface ApiService {
@POST("/api/registration")
Call<ResponseModel> registerResponse(@Body RequestModel loginData);
}
My method of hitting api -
RequestModel contactsModel = new RequestModel();
contactsModel.setFullName(username);
contactsModel.setGender(gender);
contactsModel.setEmail(email);
contactsModel.setDeviceType("ios");
contactsModel.setDeviceId("adssads90ads89afyh89sayfs89afs90afys890afsd");
List<Double> list = new ArrayList<>();
list.add(30.98877);
list.add(72.857564);
contactsModel.setLoc(list);
apiService = RestClient.getClient().create(ApiService.class);
Call<ResponseModel> getAllServerContacts = apiService.registerResponse(contactsModel);
getAllServerContacts.enqueue(new Callback<ResponseModel>() {
@Override
public void onResponse(Call<ResponseModel> responseModel, Response<ResponseModel> response) {
Alerts.dismissLoadingDialog();
try {
if (response.isSuccessful()) {
ResponseModel contactsVerified = response.body();
SignupModel signupModel = contactsVerified.getSignupModel();
String name = signupModel.getFullName();
} else {
Log.e("nOt", "Successful");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseModel> call, Throwable t) {
Alerts.dismissLoadingDialog();
Log.e("nOt", "Successful");
}
});
Location params are not going correct they ate receiving as ['30.5234234', '75.4645646545'] instead of [30.5234234, 75.4645646545].
Please let me know how to do this in case of retrofit.
Thanks