diff options
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r-- | src/org/traccar/database/QueryBuilder.java | 41 |
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); + } } } }); |