diff options
Diffstat (limited to 'src/org/traccar/model/Device.java')
-rw-r--r-- | src/org/traccar/model/Device.java | 31 |
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(); + } + } |