Created
September 9, 2015 22:59
-
-
Save anonymous/06cad6b5a26ffc10d74c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DossierParser { | |
public static BookDocument parseJSON(GsonBuilder builder, String location) { | |
builder.registerTypeAdapter(BookDocument.class, new BookDeserializer()); | |
builder.registerTypeAdapter(IPage.class, new PageDeserializer()); | |
Gson gson = builder.create(); | |
ResourceLocation rloc = new ResourceLocation(Main.MODID, location); | |
try { | |
LogHelper.info("Trying to read in JSON File...."); | |
InputStream stream = Minecraft.getMinecraft().getResourceManager().getResource(rloc).getInputStream(); | |
LogHelper.info(stream == null ? "Stream is null!" : "Stream is not null."); | |
Reader reader = new InputStreamReader(stream, "UTF-8"); | |
BookDocument doc = gson.fromJson(reader, BookDocument.class); | |
return doc; | |
} | |
catch(Exception e) { | |
LogHelper.info("Failed to read JSON file!"); | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment