From 9003ace487c4b3dc617181531c0f22dd4fdbf7a5 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 28 Jun 2016 12:39:39 +0500 Subject: JsonConverter.objectToJson now can return Lists of objects or primitives --- src/org/traccar/web/JsonConverter.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') 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(); -- cgit v1.2.3