Last active
May 10, 2016 11:17
-
-
Save ishmaelmakitla/554b80010b9850ef7b74dbf3cc44faa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment