We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 306a079 commit fd7d9d4Copy full SHA for fd7d9d4
algorithm-exercises-java/src/main/java/util/JsonLoader.java
@@ -0,0 +1,32 @@
1
+package util;
2
+
3
+import com.fasterxml.jackson.databind.ObjectMapper;
4
+import java.io.File;
5
+import java.io.IOException;
6
+import java.util.List;
7
8
+/**
9
+ * JsonLoader.
10
+ */
11
+public final class JsonLoader {
12
13
+ private JsonLoader() {}
14
15
+ /**
16
+ * loadJson.
17
18
+ public static <T> List<T> loadJson(String path, Class<T> type) throws IOException {
19
+ ObjectMapper objectMapper = new ObjectMapper();
20
21
+ File file = new File(
22
+ JsonLoader.class.getClassLoader()
23
+ .getResource(path)
24
+ .getFile()
25
+ );
26
27
+ ObjectMapper mapper = new ObjectMapper();
28
+ return mapper.readerForListOf(type)
29
+ .readValue(objectMapper.readTree(file));
30
+ }
31
32
+}
0 commit comments