diff options
author | Abyss777 <abyss@fox5.ru> | 2016-06-28 12:39:39 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-06-28 12:39:39 +0500 |
commit | 9003ace487c4b3dc617181531c0f22dd4fdbf7a5 (patch) | |
tree | 5f6d9769c95686e22a6590486237c31d44893c44 /src | |
parent | 61b2486353c742afe6214f0a0c5c2e9956ea3b97 (diff) | |
download | trackermap-server-9003ace487c4b3dc617181531c0f22dd4fdbf7a5.tar.gz trackermap-server-9003ace487c4b3dc617181531c0f22dd4fdbf7a5.tar.bz2 trackermap-server-9003ace487c4b3dc617181531c0f22dd4fdbf7a5.zip |
JsonConverter.objectToJson now can return Lists of objects or primitives
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/web/JsonConverter.java | 21 |
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(); |