aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/JsonConverter.java
diff options
context:
space:
mode:
authorRafael Guterres <guterresrafael@gmail.com>2015-11-21 01:57:46 -0200
committerRafael Guterres <guterresrafael@gmail.com>2015-11-21 01:57:46 -0200
commitf5a266953e53a7f1785bcb584759582621ec9de3 (patch)
tree06aed01befc06db1384d731d5d17ee897335c302 /src/org/traccar/web/JsonConverter.java
parentcfe237cf26c6309b8431b3b81d589628ae363804 (diff)
downloadtrackermap-server-f5a266953e53a7f1785bcb584759582621ec9de3.tar.gz
trackermap-server-f5a266953e53a7f1785bcb584759582621ec9de3.tar.bz2
trackermap-server-f5a266953e53a7f1785bcb584759582621ec9de3.zip
Add support to generic resources and refactor in classes to support types and commandpattern.
Diffstat (limited to 'src/org/traccar/web/JsonConverter.java')
-rw-r--r--src/org/traccar/web/JsonConverter.java13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java
index b19894dd6..d39e6b488 100644
--- a/src/org/traccar/web/JsonConverter.java
+++ b/src/org/traccar/web/JsonConverter.java
@@ -34,8 +34,8 @@ import javax.json.JsonValue;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
+import org.traccar.helper.Clazz;
import org.traccar.helper.Log;
-import org.traccar.model.Factory;
import org.traccar.model.MiscFormatter;
public final class JsonConverter {
@@ -49,17 +49,15 @@ public final class JsonConverter {
return DATE_FORMAT.parseDateTime(value).toDate();
}
- public static <T extends Factory> T objectFromJson(Reader reader, T prototype) throws ParseException {
+ public static <T> T objectFromJson(Reader reader, Class<T> clazz) throws ParseException {
try (JsonReader jsonReader = Json.createReader(reader)) {
- return objectFromJson(jsonReader.readObject(), prototype);
+ return objectFromJson(jsonReader.readObject(), clazz);
}
}
- public static <T extends Factory> T objectFromJson(JsonObject json, T prototype) {
- T object = (T) prototype.create();
-
+ public static <T> T objectFromJson(JsonObject json, Class<T> clazz) {
+ T object = Clazz.newInstance(clazz);
Method[] methods = object.getClass().getMethods();
-
for (final Method method : methods) {
if (method.getName().startsWith("set") && method.getParameterTypes().length == 1) {
@@ -91,7 +89,6 @@ public final class JsonConverter {
}
}
}
-
return object;
}