Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package za.co.ishlema.blog.examples;
- import java.io.Serializable;
- import java.util.UUID;
- import com.google.gson.Gson;
- /**
- * This class represents the user of the app.
- * Its serialized JSON is stored in the Shared Preferences (if the user elects a 'remember me' option when loging in)
- *
- * @author Ishmael Makitla
- *
- */
- public class MyUser implements Serializable{
- private static final long serialVersionUID = 1931512940052357382L;
- private UUID id;
- private String username;
- private String password;
- private String email;
- private String role;
- public MyUser(UUID id, String username, String password) {
- this.id = id;
- this.username = username;
- this.password = password;
- }
- public UUID getId() {
- return id;
- }
- public void setId(UUID id) {
- this.id = id;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getRole() {
- return role;
- }
- public void setRole(String role) {
- this.role = role;
- }
- /**
- * Override the toString method to return the JSON-format of the User Model.
- * The user model is stored in preferences in the JSON Format as String.
- */
- @Override
- public String toString() {
- return (new Gson()).toJson(this, MyUser.class);
- }
- /**
- * Deserializing the JSON string into an Object
- * @param userJSON
- * @return
- */
- public static MyUser asMyUser(String userJSON) {
- return (new Gson()).fromJson(userJSON, MyUser.class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement