aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-06-28 12:39:39 +0500
committerAbyss777 <abyss@fox5.ru>2016-06-28 12:39:39 +0500
commit9003ace487c4b3dc617181531c0f22dd4fdbf7a5 (patch)
tree5f6d9769c95686e22a6590486237c31d44893c44
parent61b2486353c742afe6214f0a0c5c2e9956ea3b97 (diff)
downloadtrackermap-server-9003ace487c4b3dc617181531c0f22dd4fdbf7a5.tar.gz
trackermap-server-9003ace487c4b3dc617181531c0f22dd4fdbf7a5.tar.bz2
trackermap-server-9003ace487c4b3dc617181531c0f22dd4fdbf7a5.zip
JsonConverter.objectToJson now can return Lists of objects or primitives
-rw-r--r--src/org/traccar/web/JsonConverter.java21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java
index 4b7719fd2..f9682f90d 100644
--- a/src/org/traccar/web/JsonConverter.java
+++ b/src/org/traccar/web/JsonConverter.java
@@ -35,6 +35,7 @@ import java.lang.reflect.Method;
import java.text.ParseException;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
import java.util.Map;
public final class JsonConverter {
@@ -129,6 +130,8 @@ public final class JsonConverter {
}
} else if (method.getReturnType().equals(Map.class)) {
json.add(name, MiscFormatter.toJson((Map) method.invoke(object)));
+ } else if (method.getReturnType().equals(List.class)) {
+ json.add(name, arrayToJson((List) method.invoke(object)));
}
} catch (IllegalAccessException | InvocationTargetException error) {
Log.warning(error);
@@ -144,7 +147,23 @@ public final class JsonConverter {
JsonArrayBuilder json = Json.createArrayBuilder();
for (Object object : array) {
- json.add(objectToJson(object));
+ switch (object.getClass().getSimpleName().toLowerCase()) {
+ case "string":
+ json.add(object.toString());
+ break;
+ case "long":
+ json.add((long) object);
+ break;
+ case "double":
+ json.add((double) object);
+ break;
+ case "boolean":
+ json.add((boolean) object);
+ break;
+ default:
+ json.add(objectToJson(object));
+ break;
+ }
}
return json.build();