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> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <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>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.10.2</version> <version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.10.2</version>
</dependency> </dependency>
<!-- BStats, used for metrics --> <!-- BStats, used for metrics -->
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>

View file

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

View file

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