diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-03 12:09:00 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-03 12:09:00 +1200 |
commit | 18127a2dfc362ffd7de4110e013a10a9f894469b (patch) | |
tree | 24ced00567acbc751985b71ffd99ce067213a34d /src/org/traccar/model | |
parent | 427113e0aabf1b8ab54288263c3e809f292a5a05 (diff) | |
download | traccar-server-18127a2dfc362ffd7de4110e013a10a9f894469b.tar.gz traccar-server-18127a2dfc362ffd7de4110e013a10a9f894469b.tar.bz2 traccar-server-18127a2dfc362ffd7de4110e013a10a9f894469b.zip |
Implmenet reflection json conversion
Diffstat (limited to 'src/org/traccar/model')
-rw-r--r-- | src/org/traccar/model/Data.java | 30 | ||||
-rw-r--r-- | src/org/traccar/model/Device.java | 35 | ||||
-rw-r--r-- | src/org/traccar/model/Position.java | 46 | ||||
-rw-r--r-- | src/org/traccar/model/User.java | 47 |
4 files changed, 10 insertions, 148 deletions
diff --git a/src/org/traccar/model/Data.java b/src/org/traccar/model/Data.java index d49bb0da6..d8f898317 100644 --- a/src/org/traccar/model/Data.java +++ b/src/org/traccar/model/Data.java @@ -15,17 +15,11 @@ */ package org.traccar.model; -import java.text.ParseException; import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import org.traccar.database.Convertable; -import org.traccar.database.ObjectConverter; -public class Data implements Convertable { +public class Data { private long id; public long getId() { return id; } @@ -57,26 +51,4 @@ public class Data implements Convertable { return MiscFormatter.toXmlString(other); } - @Override - public JsonObject toJson() { - JsonObjectBuilder json = Json.createObjectBuilder(); - json.add("id", id); - json.add("protocol", protocol); - json.add("deviceId", deviceId); - json.add("serverTime", ObjectConverter.dateFormat.format(serverTime)); - json.add("deviceTime", ObjectConverter.dateFormat.format(deviceTime)); - //json.add("extendedInfo", extendedInfo); - return json.build(); - } - - @Override - public void fromJson(JsonObject json) throws ParseException { - id = json.getJsonNumber("id").longValue(); - protocol = json.getString("protocol"); - deviceId = json.getJsonNumber("deviceId").longValue(); - serverTime = ObjectConverter.dateFormat.parse(json.getString("serverTime")); - deviceTime = ObjectConverter.dateFormat.parse(json.getString("deviceTime")); - //extendedInfo = json.getString("extendedInfo"); - } - } diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java index 2fb26d282..b40e694b8 100644 --- a/src/org/traccar/model/Device.java +++ b/src/org/traccar/model/Device.java @@ -15,18 +15,9 @@ */ package org.traccar.model; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.ParseException; import java.util.Date; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import org.traccar.database.Convertable; -import org.traccar.database.ObjectConverter; -import org.traccar.helper.Log; -public class Device implements Convertable, Factory { +public class Device implements Factory { @Override public Device create() { @@ -53,28 +44,4 @@ public class Device implements Convertable, Factory { private long dataId; - @Override - public JsonObject toJson() { - JsonObjectBuilder json = Json.createObjectBuilder(); - ObjectConverter.putLong(json, "id", id); - ObjectConverter.putString(json, "name", name); - ObjectConverter.putString(json, "uniqueId", uniqueId); - ObjectConverter.putString(json, "status", status); - ObjectConverter.putDate(json, "lastUpdate", lastUpdate); - ObjectConverter.putLong(json, "positionId", positionId); - ObjectConverter.putLong(json, "dataId", dataId); - return json.build(); - } - - @Override - public void fromJson(JsonObject json) throws ParseException { - id = ObjectConverter.getLong(json, "id"); - name = ObjectConverter.getString(json, "name"); - uniqueId = ObjectConverter.getString(json, "uniqueId"); - status = ObjectConverter.getString(json, "status"); - lastUpdate = ObjectConverter.getDate(json, "lastUpdate"); - positionId = ObjectConverter.getLong(json, "positionId"); - dataId = ObjectConverter.getLong(json, "dataId"); - } - } diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index c3fe60fc0..21951d115 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -15,17 +15,11 @@ */ package org.traccar.model; -import java.text.ParseException; import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import org.traccar.database.Convertable; -import org.traccar.database.ObjectConverter; -public class Position implements Convertable { +public class Position { private long id; public long getId() { return id; } @@ -94,42 +88,4 @@ public class Position implements Convertable { return MiscFormatter.toXmlString(other); } - @Override - public JsonObject toJson() { - JsonObjectBuilder json = Json.createObjectBuilder(); - json.add("id", id); - json.add("protocol", protocol); - json.add("deviceId", deviceId); - json.add("serverTime", ObjectConverter.dateFormat.format(serverTime)); - json.add("deviceTime", ObjectConverter.dateFormat.format(deviceTime)); - json.add("fixTime", ObjectConverter.dateFormat.format(fixTime)); - json.add("valid", valid); - json.add("latitude", latitude); - json.add("longitude", longitude); - json.add("altitude", altitude); - json.add("speed", speed); - json.add("course", course); - json.add("address", address); - //json.add("extendedInfo", extendedInfo); - return json.build(); - } - - @Override - public void fromJson(JsonObject json) throws ParseException { - id = json.getJsonNumber("id").longValue(); - protocol = json.getString("protocol"); - deviceId = json.getJsonNumber("deviceId").longValue(); - serverTime = ObjectConverter.dateFormat.parse(json.getString("serverTime")); - deviceTime = ObjectConverter.dateFormat.parse(json.getString("deviceTime")); - fixTime = ObjectConverter.dateFormat.parse(json.getString("fixTime")); - valid = json.getBoolean("valid"); - latitude = json.getJsonNumber("latitude").doubleValue(); - longitude = json.getJsonNumber("longitude").doubleValue(); - altitude = json.getJsonNumber("altitude").doubleValue(); - speed = json.getJsonNumber("speed").doubleValue(); - course = json.getJsonNumber("course").doubleValue(); - address = json.getString("address"); - //extendedInfo = json.getString("extendedInfo"); - } - } diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index 02e5c0c4f..ea4617e54 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -15,18 +15,19 @@ */ package org.traccar.model; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import org.traccar.database.Convertable; - -public class User implements Convertable { +public class User { private long id; + public long getId() { return id; } + public void setId(long id) { this.id = id; } private String email; + public String getEmail() { return email; } + public void setEmail(String email) { this.email = email; } private String password; + public String getPassword() { return password; } + public void setPassword(String password) { this.password = password; } private boolean readonly; @@ -46,38 +47,4 @@ public class User implements Convertable { 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(); - } - } |