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.java31
1 files changed, 7 insertions, 24 deletions
diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java
index 2ef61fb13..8bf5607fb 100644
--- a/src/org/traccar/web/JsonConverter.java
+++ b/src/org/traccar/web/JsonConverter.java
@@ -35,7 +35,6 @@ import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.traccar.helper.Log;
-import org.traccar.model.Factory;
import org.traccar.model.MiscFormatter;
public final class JsonConverter {
@@ -43,32 +42,12 @@ public final class JsonConverter {
private JsonConverter() {
}
- private static <T> T newClassInstance(Class<T> clazz) {
- try {
- return clazz.newInstance();
- } catch (InstantiationException | IllegalAccessException e) {
- throw new IllegalArgumentException();
- }
- }
-
private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime();
public static Date parseDate(String value) {
return DATE_FORMAT.parseDateTime(value).toDate();
}
- public static <T extends Factory> T objectFromJson(Reader reader, T prototype) throws ParseException {
- try (JsonReader jsonReader = Json.createReader(reader)) {
- return objectFromJson(jsonReader.readObject(), prototype);
- }
- }
-
- public static <T extends Factory> T objectFromJson(JsonObject json, T prototype) {
- T object = (T) prototype.create();
- Method[] methods = object.getClass().getMethods();
- return objectFromJson(json, object, methods);
- }
-
public static <T> T objectFromJson(Reader reader, Class<T> clazz) throws ParseException {
try (JsonReader jsonReader = Json.createReader(reader)) {
return objectFromJson(jsonReader.readObject(), clazz);
@@ -76,9 +55,13 @@ public final class JsonConverter {
}
public static <T> T objectFromJson(JsonObject json, Class<T> clazz) {
- T object = newClassInstance(clazz);
- Method[] methods = object.getClass().getMethods();
- return objectFromJson(json, object, methods);
+ try {
+ T object = clazz.newInstance();
+ Method[] methods = object.getClass().getMethods();
+ return objectFromJson(json, object, methods);
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new IllegalArgumentException();
+ }
}
private static <T> T objectFromJson(JsonObject json, T object, Method[] methods) {