aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/model/Device.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/Device.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/Device.java')
-rw-r--r--src/org/traccar/model/Device.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java
index 273faebcf..4e2f57690 100644
--- a/src/org/traccar/model/Device.java
+++ b/src/org/traccar/model/Device.java
@@ -15,9 +15,14 @@
*/
package org.traccar.model;
+import java.text.ParseException;
import java.util.Date;
+import javax.json.Json;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import org.traccar.database.JsonConvertable;
-public class Device {
+public class Device implements JsonConvertable {
private long id;
public long getId() { return id; }
@@ -39,4 +44,28 @@ public class Device {
private long dataId;
+ @Override
+ public JsonObject toJson() {
+ JsonObjectBuilder json = Json.createObjectBuilder();
+ json.add("id", id);
+ json.add("name", name);
+ json.add("uniqueId", uniqueId);
+ json.add("status", status);
+ json.add("lastUpdate", dateFormat.format(lastUpdate));
+ json.add("positionId", positionId);
+ json.add("dataId", dataId);
+ return json.build();
+ }
+
+ @Override
+ public void fromJson(JsonObject json) throws ParseException {
+ id = json.getJsonNumber("id").longValue();
+ name = json.getString("name");
+ uniqueId = json.getString("uniqueId");
+ status = json.getString("status");
+ lastUpdate = dateFormat.parse(json.getString("lastUpdate"));
+ positionId = json.getJsonNumber("positionId").longValue();
+ dataId = json.getJsonNumber("dataId").longValue();
+ }
+
}