#JSON/GSON and Datatypes

1 messages · Page 1 of 1 (latest)

snow obsidian
#

I'm relatively new to some of the more niche features of Java, such as using google's json loader, any tips or advice on how to get this working?

public Map<UUID, Map<String, String>> loadResources() {
        Gson gson = new Gson();
        File file = new File(Chunktycoon.getInstance().getDataFolder().getAbsolutePath() + "/resources.json");
        if (file.exists()) {
            try {
                Reader reader = new FileReader(file);
                Type listType = new TypeToken<Map<UUID, Map<String, String>>>() {}.getType();
                Map<UUID, Map<String, String>> resources = gson.fromJson(reader, listType);
                Bukkit.getLogger().info("Loaded in resources");
                return resources;
                } catch (IOException e) {
                Bukkit.getLogger().info("Error loading resources");
                return null;
                }
            } else if (true) {
                Bukkit.getLogger().info("No resources to load!");
                return null;
                } 
        return null;
    }