diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-06-28 21:12:13 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-28 21:12:13 +1200 |
commit | 8cb9fb298578bc4870a360d258172ef80cffeee3 (patch) | |
tree | c45a2bb07413638ef1c295047bc31e230de3c7ff | |
parent | aaff3f18b8dbc44287a237cd39eba91b77705f82 (diff) | |
parent | 9003ace487c4b3dc617181531c0f22dd4fdbf7a5 (diff) | |
download | traccar-server-8cb9fb298578bc4870a360d258172ef80cffeee3.tar.gz traccar-server-8cb9fb298578bc4870a360d258172ef80cffeee3.tar.bz2 traccar-server-8cb9fb298578bc4870a360d258172ef80cffeee3.zip |
Merge pull request #2057 from Abyss777/master
JsonConverter.objectToJson now can return Lists
-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(); |