diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-18 13:05:49 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-18 13:05:49 +1200 |
commit | f35ce1eda48511c610e32ef481440160966ead1f (patch) | |
tree | f0b7ba1934e508a4675900c480a792c0c589244e /src | |
parent | 5c25c48c8db367097f5ee1e9bf6d7e5435e8665a (diff) | |
download | trackermap-server-f35ce1eda48511c610e32ef481440160966ead1f.tar.gz trackermap-server-f35ce1eda48511c610e32ef481440160966ead1f.tar.bz2 trackermap-server-f35ce1eda48511c610e32ef481440160966ead1f.zip |
Implement json other decoding
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/model/MiscFormatter.java | 5 | ||||
-rw-r--r-- | src/org/traccar/web/JsonConverter.java | 9 |
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) { } |