package utils.json;
import play.Logger;
import com.google.gson.JsonObject;
import models.User;;
public class UserResidenceJSON extends AbstractJSON {
public UserResidenceJSON(User user) {
put("id", user.id);
put("username", user.username);
put("admin", user.isAdmin());
put("access", user.access);
}
public UserResidenceJSON(JsonObject object) {
Long id = null;
String username = null;
String password = null;
try {
id = object.get("id") != null && !("").equals(object.get("id").getAsString()) ? object.get("id").getAsLong() : null;
username = object.get("username").getAsString();
password = object.get("password").getAsString();
} catch(Exception e) {
Logger.error("Error parsing UserResidenceJSON from JSON object: %s", object.toString());
}
put("id", id);
put("username", username);
put("password", password);
put("admin", Boolean.FALSE);
put("access",Boolean.TRUE);
}
public User getUser() {
User user = new User();
user.id = (Long) get("id");
user.username = (String) get("username");
user.password = (String) get("password");
user.access = (Boolean) get("access");
return user;
}
}