Skip to content

Instantly share code, notes, and snippets.

@yeikel
Last active April 25, 2022 16:35
Show Gist options
  • Save yeikel/9de78ce94fd0c3b8c54e051142082727 to your computer and use it in GitHub Desktop.
Save yeikel/9de78ce94fd0c3b8c54e051142082727 to your computer and use it in GitHub Desktop.
Read JSON file to an Object
public static <T> T readJSON(final String path, Type typeOfT) {
try (final BufferedReader br = Files.newBufferedReader(Paths.get(path))) {
return new Gson().fromJson(br, typeOfT);
} catch (final IOException e) {
throw new RuntimeException("Error reading configuration file", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment