Skip to content

Commit 262fad5

Browse files
add JsonFileToObject logging
1 parent fbc639d commit 262fad5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/helper/JsonFileToObject.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57

68
import java.io.File;
9+
import java.util.Objects;
710

811
public class JsonFileToObject {
912

13+
private static final Logger LOG = LoggerFactory.getLogger(JsonFileToObject.class);
1014
private static final ObjectMapper mapper = new ObjectMapper()
1115
.registerModule(new JavaTimeModule());
1216

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

0 commit comments

Comments
 (0)