VladMorzhanov
9/23/2017 - 2:56 PM

Android model class example for realm and retrofit 2.

Android model class example for realm and retrofit 2.

package com.dev.data.models;

import com.google.gson.annotations.SerializedName;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;


/**
 * Model class for a User extends RealmObject and supports gson annotations for Retrofit.
 */
public class User extends RealmObject {

    @PrimaryKey
    private long id;

    @SerializedName("_id")
    private String _id;

    @SerializedName("photoUrl")
    private String photoUrl;

    @SerializedName("name")
    private String name;

    @SerializedName("email")
    private String email;

    @SerializedName("gender")
    private String gender;

    /*
    Only local variables
     */

    private boolean userState;

    public User() {
    }

    public User(long id, String _id, String photoUrl, String name, String email) {
        this.id = id;
        this._id = _id;
        this.photoUrl = photoUrl;
        this.name = name;
        this.email = email;
        this.userState = userState;
    }

    public User(String _id, String token, String photoUrl, String name, String email){
        this._id = _id;
        this.token = token;
        this.photoUrl = photoUrl;
        this.name = name;
        this.email = email;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String get_id() {
        return _id;
    }

    public void set_id(String _id) {
        this._id = _id;
    }

    public String getPhotoUrl() {
        return photoUrl;
    }

    public void setPhotoUrl(String photoUrl) {
        this.photoUrl = photoUrl;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}