diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-27 12:52:33 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-27 12:52:33 +1200 |
commit | 3083db3929e27933d3ab5eab9fa0c1e221e94eec (patch) | |
tree | 15db7705ecb90dabafb8719c9b93861982a5d91b /src/org/traccar/model/Data.java | |
parent | 27055e0bf5f544552c227da10badff34a71cfb70 (diff) | |
download | traccar-server-3083db3929e27933d3ab5eab9fa0c1e221e94eec.tar.gz traccar-server-3083db3929e27933d3ab5eab9fa0c1e221e94eec.tar.bz2 traccar-server-3083db3929e27933d3ab5eab9fa0c1e221e94eec.zip |
Implement JSON conversion
Diffstat (limited to 'src/org/traccar/model/Data.java')
-rw-r--r-- | src/org/traccar/model/Data.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/org/traccar/model/Data.java b/src/org/traccar/model/Data.java index ce23154c2..1cef813a3 100644 --- a/src/org/traccar/model/Data.java +++ b/src/org/traccar/model/Data.java @@ -15,9 +15,15 @@ */ 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; +import static org.traccar.database.JsonConvertable.dateFormat; -public class Data { +public class Data implements JsonConvertable { private long id; public long getId() { return id; } @@ -39,4 +45,24 @@ public class Data { public String getExtendedInfo() { return extendedInfo; } public void setExtendedInfo(String extendedInfo) { this.extendedInfo = extendedInfo; } + @Override + public JsonObject toJson() { + JsonObjectBuilder json = Json.createObjectBuilder(); + json.add("id", id); + json.add("deviceId", deviceId); + json.add("serverTime", dateFormat.format(serverTime)); + json.add("deviceTime", dateFormat.format(deviceTime)); + //json.add("extendedInfo", extendedInfo); + return json.build(); + } + + @Override + public void fromJson(JsonObject json) throws ParseException { + id = json.getJsonNumber("id").longValue(); + deviceId = json.getJsonNumber("deviceId").longValue(); + serverTime = dateFormat.parse(json.getString("serverTime")); + deviceTime = dateFormat.parse(json.getString("deviceTime")); + //extendedInfo = json.getString("extendedInfo"); + } + } |