aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/JsonConverter.java
diff options
context:
space:
mode:
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 c01ce8bd6..a8b68613b 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;
}