Advertisement
Guest User

account

a guest
Nov 12th, 2018
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import org.json.simple.JSONObject;
  2.  
  3. public class Account {
  4.  
  5.     private int id;
  6.     private String username;
  7.     private String name;
  8.     private String email;
  9.     private String password;
  10.  
  11.     public Account (int id, String username, String name, String email, String password) {
  12.         this.id = id;
  13.         this.username = username;
  14.         this.name = name;
  15.         this.email = email;
  16.         this.password = password;
  17.     }
  18.  
  19.     public int getId() {
  20.         return id;
  21.     }
  22.  
  23.     public String getUsername() {
  24.         return username;
  25.     }
  26.  
  27.     public String getName() {
  28.         return name;
  29.     }
  30.  
  31.     public String getEmail() {
  32.         return email;
  33.     }
  34.  
  35.     public String getPassword() {
  36.         return password;
  37.     }
  38.  
  39.     public static Account fromJSON (JSONObject account) {
  40.         return new Account (
  41.                 ((Long) account.get("id")).intValue(), //  ((Long) account.get("id")).intValue(),
  42.                 (String) account.get("username"),
  43.                 (String) account.get("name"),
  44.                 (String) account.get("email"),
  45.                 (String) account.get("password")
  46.         );
  47.     }
  48.  
  49.  
  50.     public JSONObject toJSON () {
  51.         JSONObject userJsonObject = new JSONObject();
  52.         userJsonObject.put("id", id);
  53.         userJsonObject.put("username", username);
  54.         userJsonObject.put("name", name);
  55.         userJsonObject.put("email", email);
  56.         userJsonObject.put("password", password);
  57.  
  58.         return userJsonObject;
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement