Skip to content

Instantly share code, notes, and snippets.

Created October 14, 2022 10:40
What would you like to do?
package org.example.repositories;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Repository;
public class FileUtils {
* Read File and return JsonNode
* @param filePath
* @return
* @throws IOException
public static JsonNode readJsonFromFile(String filePath) throws IOException {
ObjectMapper mapper = new ObjectMapper();
URL res = FileUtils.class.getClassLoader().getResource(filePath);
if (res == null) {
throw new IllegalArgumentException(String.format("File not found! - %s", filePath));
return mapper.readTree(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment