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/database/ObjectConverter.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/database/ObjectConverter.java')
-rw-r--r-- | src/org/traccar/database/ObjectConverter.java | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/src/org/traccar/database/ObjectConverter.java b/src/org/traccar/database/ObjectConverter.java index bd5b03064..4ab83faec 100644 --- a/src/org/traccar/database/ObjectConverter.java +++ b/src/org/traccar/database/ObjectConverter.java @@ -15,37 +15,19 @@ */ package org.traccar.database; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.Collection; import javax.json.Json; import javax.json.JsonArray; import javax.json.JsonArrayBuilder; -import javax.json.JsonObjectBuilder; -import org.traccar.model.Position; public class ObjectConverter { - private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ"); - - public static JsonArray convert(Collection<Position> positions) { + public static JsonArray convert(Collection<? extends JsonConvertable> collection) { JsonArrayBuilder array = Json.createArrayBuilder(); - for (Position position : positions) { - JsonObjectBuilder object = Json.createObjectBuilder(); - - //object.add("id", position.getId()); - object.add("time", dateFormat.format(position.getFixTime())); - object.add("valid", position.getValid()); - object.add("latitude", position.getLatitude()); - object.add("longitude", position.getLongitude()); - object.add("altitude", position.getAltitude()); - object.add("speed", position.getSpeed()); - object.add("course", position.getCourse()); - //object.add("other", position.getExtendedInfo()); - - array.add(object.build()); + for (JsonConvertable object : collection) { + array.add(object.toJson()); } return array.build(); |