2022-01-23 17:40:49 +01:00
|
|
|
package config;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import res.DataController;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
|
|
public class ConfigLoader {
|
|
|
|
|
|
|
|
public static Config load(){
|
|
|
|
try {
|
|
|
|
String jsonString = Files.readString(Paths.get("config.json"));
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
objectMapper.findAndRegisterModules();
|
|
|
|
return objectMapper.readValue(jsonString, Config.class);
|
|
|
|
} catch (IOException e) {
|
2022-01-25 19:20:06 +01:00
|
|
|
System.out.println("config.json missing");
|
2022-01-23 17:40:49 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void save(Config config){
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
objectMapper.findAndRegisterModules();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Files.writeString(Paths.get(
|
|
|
|
"config.json"),
|
|
|
|
objectMapper.writeValueAsString(config)
|
|
|
|
);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|