Skip to content

Commit 7a47235

Browse files
add logging and handle errors in JsonFileToObject
1 parent c766d4f commit 7a47235

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package uk.gov.hmcts.cp.pact.helper;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
56

67
import java.io.File;
8+
import java.util.Objects;
79

810
public class JsonFileToObject {
911

10-
private static final ObjectMapper mapper = new ObjectMapper()
11-
.registerModule(new JavaTimeModule());
12+
private static final Logger LOG = LoggerFactory.getLogger(JsonFileToObject.class);
13+
private static final ObjectMapper mapper = new ObjectMapper();
1214

1315
public static <T> T readJsonFromResources(String fileName, Class<T> clazz) throws Exception {
14-
File file = new File(JsonFileToObject.class.getClassLoader().getResource(fileName).toURI());
16+
File file;
17+
try{
18+
file = new File(Objects.requireNonNull(JsonFileToObject.class.getClassLoader().getResource(fileName)).toURI());
19+
} catch (Exception e) {
20+
LOG.atError().log("Error loading file: {}", fileName, e);
21+
throw e;
22+
}
1523
return mapper.readValue(file, clazz);
1624
}
1725
}

0 commit comments

Comments
 (0)