Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2015 22:59
Show Gist options
  • Save anonymous/06cad6b5a26ffc10d74c to your computer and use it in GitHub Desktop.
Save anonymous/06cad6b5a26ffc10d74c to your computer and use it in GitHub Desktop.
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