Starter Guide to Retrofit - Android Studio- Part Two

Starter Guide to Retrofit - Android Studio- Part Two

Setting up the model class.

Welcome to part two of our series. You should check out part one, to follow along.

The Modal Class is the Java class that replicates or resembles the structure of the object we are to receive from the JSON response in our API call.

To keep this simple, we will create our modal class in our main package folder (where the MainActivity.java file is. ). We will name it 'ProfileModel' to model the data of a user profile, retrieved from our son object.

In order to have this class nicely configured, we should take a look at the properties of the object being returned. If you followed along with my post on mocky, you will notice that we only have one JSON object - (profile detail), so we do not need to create or display a list. We will do this in our advanced series later on.

Ode.png

Because our class serves as a template to the JSON object, our class should have the following properties as listed.


    private String name;
    private String company;
    private String blog;
    private String location;
    private String bio;

The full class should look like this with the getters.

public class ProfileModel {

    private String name;
    private String company;
    private String blog;
    private String location;
    private String bio;


    public String getName() {
        return name;
    }

    public String getCompany() {
        return company;
    }

    public String getBlog() {
        return blog;
    }

    public String getLocation() {
        return location;
    }

    public String getBio() {
        return bio;
    }
}

Our modal class is set. See you in my next guide.