From 3083db3929e27933d3ab5eab9fa0c1e221e94eec Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 27 Apr 2015 12:52:33 +1200 Subject: Implement JSON conversion --- src/org/traccar/database/ObjectConverter.java | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'src/org/traccar/database/ObjectConverter.java') 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 positions) { + public static JsonArray convert(Collection 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(); -- cgit v1.2.3