aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-19 08:01:20 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-12-19 08:01:20 +1300
commit54e738d3281a463a0ea3fcf2026c2464529a9b58 (patch)
tree65e924f480d6489a5939d2f289c354240fd68e59 /src/org/traccar/database
parent99f09134fb9c710114296d603c97a76f5cfb0d2a (diff)
downloadtraccar-server-54e738d3281a463a0ea3fcf2026c2464529a9b58.tar.gz
traccar-server-54e738d3281a463a0ea3fcf2026c2464529a9b58.tar.bz2
traccar-server-54e738d3281a463a0ea3fcf2026c2464529a9b58.zip
Remove own JSON converter
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/QueryBuilder.java41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index 201240f2f..127229700 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -15,15 +15,13 @@
*/
package org.traccar.database;
+import com.fasterxml.jackson.core.JsonProcessingException;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.MiscFormatter;
-import javax.json.Json;
-import javax.json.JsonReader;
-import javax.json.stream.JsonParsingException;
import javax.sql.DataSource;
-import java.io.StringReader;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
@@ -279,14 +277,15 @@ public final class QueryBuilder {
setDate(name, (Date) method.invoke(object));
} else if (method.getReturnType().equals(byte[].class)) {
setBlob(name, (byte[]) method.invoke(object));
- } else if (method.getReturnType().equals(Map.class)) {
- if (Context.getConfig().getBoolean("database.xml")) {
+ } else {
+ if (method.getReturnType().equals(Map.class)
+ && Context.getConfig().getBoolean("database.xml")) {
setString(name, MiscFormatter.toXmlString((Map) method.invoke(object)));
} else {
- setString(name, MiscFormatter.toJsonString((Map) method.invoke(object)));
+ setString(name, Context.getObjectMapper().writeValueAsString(method.invoke(object)));
}
}
- } catch (IllegalAccessException | InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException | JsonProcessingException error) {
Log.warning(error);
}
}
@@ -380,28 +379,28 @@ public final class QueryBuilder {
}
}
});
- } else if (parameterType.equals(Map.class)) {
+ } else if (parameterType.equals(byte[].class)) {
processors.add(new ResultSetProcessor<T>() {
@Override
public void process(T object, ResultSet resultSet) throws SQLException {
- String value = resultSet.getString(name);
- if (value != null) {
- try (JsonReader reader = Json.createReader(new StringReader(value))) {
- method.invoke(object, MiscFormatter.fromJson(reader.readObject()));
- } catch (IllegalAccessException | InvocationTargetException | JsonParsingException error) {
- Log.warning(error);
- }
+ try {
+ method.invoke(object, resultSet.getBytes(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ Log.warning(error);
}
}
});
- } else if (parameterType.equals(byte[].class)) {
+ } else {
processors.add(new ResultSetProcessor<T>() {
@Override
public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getBytes(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
+ String value = resultSet.getString(name);
+ if (value != null) {
+ try {
+ method.invoke(object, Context.getObjectMapper().readValue(value, Map.class));
+ } catch (InvocationTargetException | IllegalAccessException | IOException error) {
+ Log.warning(error);
+ }
}
}
});