aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/JsonConverter.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-07-18 13:05:49 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-07-18 13:05:49 +1200
commitf35ce1eda48511c610e32ef481440160966ead1f (patch)
treef0b7ba1934e508a4675900c480a792c0c589244e /src/org/traccar/web/JsonConverter.java
parent5c25c48c8db367097f5ee1e9bf6d7e5435e8665a (diff)
downloadtrackermap-server-f35ce1eda48511c610e32ef481440160966ead1f.tar.gz
trackermap-server-f35ce1eda48511c610e32ef481440160966ead1f.tar.bz2
trackermap-server-f35ce1eda48511c610e32ef481440160966ead1f.zip
Implement json other decoding
Diffstat (limited to 'src/org/traccar/web/JsonConverter.java')
-rw-r--r--src/org/traccar/web/JsonConverter.java9
1 files changed, 5 insertions, 4 deletions
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) {
}