Fixed jackson issues

This commit is contained in:
stijnb1234 2020-02-24 18:10:37 +01:00
parent 3e8df97368
commit 9c56e5b38d
4 changed files with 16 additions and 19 deletions

15
pom.xml
View file

@ -177,19 +177,20 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.2</version>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.10.2</version>
<version>2.9.6</version>
</dependency>
<!-- BStats, used for metrics -->
<dependency>
<groupId>org.bstats</groupId>

View file

@ -21,6 +21,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
@ -355,7 +356,7 @@ public class V10LiftCommand implements CommandExecutor {
try {
V10LiftPlugin.getDBManager().save();
V10LiftPlugin.getDBManager().load();
} catch (SQLException | JsonProcessingException e) {
} catch (SQLException | IOException e) {
e.printStackTrace();
}

View file

@ -1,14 +1,12 @@
package nl.SBDeveloper.V10Lift.Managers;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDevelopment.SBUtilities.Data.SQLiteDB;
import org.bukkit.Bukkit;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -34,7 +32,7 @@ public class DBManager {
}
}
public void load() throws SQLException, JsonProcessingException {
public void load() throws SQLException, IOException {
String query = "SELECT * FROM lifts";
PreparedStatement statement = con.prepareStatement(query);
ResultSet liftSet = statement.executeQuery();
@ -50,9 +48,7 @@ public class DBManager {
byte[] blob = liftSet.getBytes("liftData");
String json = new String(blob);
ObjectMapper mapper = new ObjectMapper()
.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
ObjectMapper mapper = new ObjectMapper();
Lift lift = mapper.readValue(json, Lift.class);
DataManager.addLift(liftSet.getString("liftName"), lift);
@ -98,9 +94,7 @@ public class DBManager {
public void save() throws JsonProcessingException {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
ObjectMapper mapper = new ObjectMapper()
.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
ObjectMapper mapper = new ObjectMapper();
byte[] blob = mapper.writeValueAsString(entry.getValue()).getBytes();

View file

@ -17,6 +17,7 @@ import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Objects;
@ -42,7 +43,7 @@ public class V10LiftPlugin extends JavaPlugin {
dbManager = new DBManager("data");
try {
dbManager.load();
} catch (SQLException | JsonProcessingException e) {
} catch (SQLException | IOException e) {
e.printStackTrace();
}