-2

Am trying to post this data on my server using retrofit on my android app but icant seem to get through how can I be helped thanks guys

Here is my APiClient

public interface VerifiedStudentJsonPlaceholder {

    @Headers("Content-Type: application/json")
    @POST("verifiedStudent")
    Call<VerifiedStudent> addVerifiedStudent(@Header("Authorization") String token_value, @Body JsonObject jsonObject);
}

hers is the typ of data that i want to post

{
    "firstname":"mutalemwa",
    "lastname":"clemence",
    "college": "SMCOSE",
    "university": "SUA",
    "phone": "078989898"
    
}
Kyle Mutta
  • 379
  • 1
  • 5
  • 16
  • 1
    Does this answer your question? [How to POST raw whole JSON in the body of a Retrofit request?](https://stackoverflow.com/questions/21398598/how-to-post-raw-whole-json-in-the-body-of-a-retrofit-request) – ADM Sep 22 '20 at 07:31

1 Answers1

1

Its easy. Just create a class for your request model. Like below:

public class Model {
    
    String firstname;
    String lastname;
    String college;
    String university;
    String phone;


    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getCollege() {
        return college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    public String getUniversity() {
        return university;
    }

    public void setUniversity(String university) {
        this.university = university;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}

Then create an object of your model and fill it And pass it to addVerifiedStudent method. Don't forget to change the method signature:

Call<VerifiedStudent> addVerifiedStudent(@Header("Authorization") String token_value, @Body Model model);
Mohammad Zarei
  • 1,773
  • 14
  • 33