Advertisement
Guest User

Untitled

a guest
May 10th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package za.co.ishlema.blog.examples;
  2.  
  3. import java.io.Serializable;
  4. import java.util.UUID;
  5. import com.google.gson.Gson;
  6.  
  7. /**
  8. * This class represents the user of the app.
  9. * Its serialized JSON is stored in the Shared Preferences (if the user elects a 'remember me' option when loging in)
  10. *
  11. * @author Ishmael Makitla
  12. *
  13. */
  14. public class MyUser implements Serializable{
  15.  
  16. private static final long serialVersionUID = 1931512940052357382L;
  17.  
  18. private UUID id;
  19. private String username;
  20. private String password;
  21. private String email;
  22. private String role;
  23.  
  24. public MyUser(UUID id, String username, String password) {
  25. this.id = id;
  26. this.username = username;
  27. this.password = password;
  28. }
  29.  
  30. public UUID getId() {
  31. return id;
  32. }
  33.  
  34. public void setId(UUID id) {
  35. this.id = id;
  36. }
  37.  
  38. public String getEmail() {
  39. return email;
  40. }
  41.  
  42. public void setEmail(String email) {
  43. this.email = email;
  44. }
  45.  
  46. public String getPassword() {
  47. return password;
  48. }
  49.  
  50. public void setPassword(String password) {
  51. this.password = password;
  52. }
  53.  
  54. public String getUsername() {
  55. return username;
  56. }
  57.  
  58. public void setUsername(String username) {
  59. this.username = username;
  60. }
  61.  
  62. public String getRole() {
  63. return role;
  64. }
  65.  
  66. public void setRole(String role) {
  67. this.role = role;
  68. }
  69.  
  70. /**
  71. * Override the toString method to return the JSON-format of the User Model.
  72. * The user model is stored in preferences in the JSON Format as String.
  73. */
  74. @Override
  75. public String toString() {
  76. return (new Gson()).toJson(this, MyUser.class);
  77. }
  78. /**
  79. * Deserializing the JSON string into an Object
  80. * @param userJSON
  81. * @return
  82. */
  83. public static MyUser asMyUser(String userJSON) {
  84. return (new Gson()).fromJson(userJSON, MyUser.class);
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement