This is the Json format I want to post using Retrofit.
{
"userTreatmentId": "string",
"informedConsentId": "string",
"other": [
{
"gdprOptionId": "string",
"value": true,
"required": true
}
]
}
This is the interface:
@POST("/api/requestSign")
Call<RequestSignResponse> requestSign(@Body SignRequest signRequest, @Path("patientGUID") String cardNumber);
This is a Sign Request model class.
public class SignRequest {
@SerializedName("userTreatmentId")
@Expose
private String userTreatmentId;
@SerializedName("informedConsentId")
@Expose
private String informedConsentId;
@SerializedName("other")
@Expose
private Other[] other = null;
public String getUserTreatmentId() {
return userTreatmentId;
}
public void setUserTreatmentId(String userTreatmentId) {
this.userTreatmentId = userTreatmentId;
}
public String getInformedConsentId() {
return informedConsentId;
}
public void setInformedConsentId(String informedConsentId) {
this.informedConsentId = informedConsentId;
}
public Other[] getOther() {
return other;
}
public void setOther(Other[] other) {
this.other = other;
}
}
This is the Other array model class for Sign Request
public class Other {
@SerializedName("gdprOptionId")
@Expose
private String gdprOptionId;
@SerializedName("value")
@Expose
private Boolean value;
@SerializedName("required")
@Expose
private Boolean required;
public String getGdprOptionId() {
return gdprOptionId;
}
public void setGdprOptionId(String gdprOptionId) {
this.gdprOptionId = gdprOptionId;
}
public Boolean getValue() {
return value;
}
public void setValue(Boolean value) {
this.value = value;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
}
What I have tried:
private void processData() {
SignRequest signRequest = new SignRequest();
signRequest.setInformedConsentId(informedConsentId);
signRequest.setUserTreatmentId(null);
signRequest.setOther(arrayList2);
ApiHelper.getService().requestSign(signRequest, PreferencesHelper.getPrefCardNumber(this))
.enqueue(new Callback<RequestSignResponse>() {
@Override
public void onResponse(Call<RequestSignResponse> call, Response<RequestSignResponse> response) {
Toast.makeText(ConsentDetailActivity.this, response.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<RequestSignResponse> call, Throwable t) {
Toast.makeText(ConsentDetailActivity.this, t.toString(), Toast.LENGTH_LONG).show();
}
});
}