aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/model/User.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-04-27 12:52:33 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-04-27 12:52:33 +1200
commit3083db3929e27933d3ab5eab9fa0c1e221e94eec (patch)
tree15db7705ecb90dabafb8719c9b93861982a5d91b /src/org/traccar/model/User.java
parent27055e0bf5f544552c227da10badff34a71cfb70 (diff)
downloadtrackermap-server-3083db3929e27933d3ab5eab9fa0c1e221e94eec.tar.gz
trackermap-server-3083db3929e27933d3ab5eab9fa0c1e221e94eec.tar.bz2
trackermap-server-3083db3929e27933d3ab5eab9fa0c1e221e94eec.zip
Implement JSON conversion
Diffstat (limited to 'src/org/traccar/model/User.java')
-rw-r--r--src/org/traccar/model/User.java45
1 files changed, 42 insertions, 3 deletions
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index 93ce111ec..a3eaf5a10 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -15,7 +15,12 @@
*/
package org.traccar.model;
-public class User {
+import javax.json.Json;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import org.traccar.database.JsonConvertable;
+
+public class User implements JsonConvertable {
private long id;
@@ -31,14 +36,48 @@ public class User {
private String language;
- private String distance_unit;
+ private String distanceUnit;
- private String speed_unit;
+ private String speedUnit;
private double latitude;
private double longitude;
private int zoom;
+
+ @Override
+ public JsonObject toJson() {
+ JsonObjectBuilder json = Json.createObjectBuilder();
+ json.add("id", id);
+ json.add("email", email);
+ json.add("password", password);
+ json.add("readonly", readonly);
+ json.add("admin", admin);
+ json.add("map", map);
+ json.add("language", language);
+ json.add("distanceUnit", distanceUnit);
+ json.add("speedUnit", speedUnit);
+ json.add("latitude", latitude);
+ json.add("longitude", longitude);
+ json.add("zoom", zoom);
+ return json.build();
+ }
+
+ @Override
+ public void fromJson(JsonObject json) {
+ id = json.getJsonNumber("id").longValue();
+ email = json.getString("email");
+ password = json.getString("password");
+ readonly = json.getBoolean("readonly");
+ admin = json.getBoolean("admin");
+ map = json.getString("map");
+ language = json.getString("language");
+ distanceUnit = json.getString("distanceUnit");
+ speedUnit = json.getString("speedUnit");
+ latitude = json.getJsonNumber("latitude").doubleValue();
+ longitude = json.getJsonNumber("longitude").doubleValue();
+ zoom = json.getJsonNumber("zoom").intValue();
+ }
}