aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/model/MiscFormatter.java5
-rw-r--r--src/org/traccar/web/JsonConverter.java9
2 files changed, 6 insertions, 8 deletions
diff --git a/src/org/traccar/model/MiscFormatter.java b/src/org/traccar/model/MiscFormatter.java
index a866f3ec7..d1e1ae959 100644
--- a/src/org/traccar/model/MiscFormatter.java
+++ b/src/org/traccar/model/MiscFormatter.java
@@ -24,7 +24,6 @@ import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonString;
import javax.json.JsonValue;
-import org.traccar.helper.Log;
/**
* Format extended tracker status
@@ -33,7 +32,7 @@ public class MiscFormatter {
private static final String xmlRootNode = "info";
- private static DecimalFormat decimalFormat = new DecimalFormat("#.##");
+ private static final DecimalFormat decimalFormat = new DecimalFormat("#.##");
private static String format(Object value) {
if (value instanceof Double || value instanceof Float) {
@@ -74,8 +73,6 @@ public class MiscFormatter {
json.add(entry.getKey(), (Double) entry.getValue());
} else if (entry.getValue() instanceof Boolean) {
json.add(entry.getKey(), (Boolean) entry.getValue());
- } else {
- Log.warning("Unknown type of data");
}
}
diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java
index 0dc4f24eb..d01b91536 100644
--- a/src/org/traccar/web/JsonConverter.java
+++ b/src/org/traccar/web/JsonConverter.java
@@ -30,6 +30,7 @@ import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
+import javax.json.JsonReader;
import javax.json.JsonValue;
import org.traccar.model.Factory;
import org.traccar.model.MiscFormatter;
@@ -43,7 +44,9 @@ public class JsonConverter {
}
public static <T extends Factory> T objectFromJson(Reader reader, T prototype) throws ParseException {
- return objectFromJson(Json.createReader(reader).readObject(), prototype);
+ try (JsonReader jsonReader = Json.createReader(reader)) {
+ return objectFromJson(jsonReader.readObject(), prototype);
+ }
}
public static <T extends Factory> T objectFromJson(JsonObject json, T prototype) throws ParseException {
@@ -72,10 +75,8 @@ public class JsonConverter {
method.invoke(object, json.getString(name));
} else if (parameterType.equals(Date.class)) {
method.invoke(object, dateFormat.parse(json.getString(name)));
- } else if (parameterType.isEnum()) {
- method.invoke(object, Enum.valueOf((Class<? extends Enum>) parameterType, json.getString(name)));
} else if (parameterType.equals(Map.class)) {
- // TODO: method.invoke(object, json.getString(name));
+ method.invoke(object, MiscFormatter.fromJson(json.getJsonObject(name)));
}
} catch (IllegalAccessException | InvocationTargetException error) {
}