Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
            }
        });
    }
Posted
Updated 26-Aug-20 9:21am
Comments
David Crow 26-Aug-20 15:09pm    
What is (not) happening, exactly?

1 solution

Given you have not shared what works and what not, following is what can guide you to what you asked in question title: How to post array in retrofit android[^]

A similar discussion elsewhere[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900