Skip to content

Instantly share code, notes, and snippets.

@luuizeduardo
Created October 14, 2022 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luuizeduardo/2407a2969cec12485ed69574cf5a7fee to your computer and use it in GitHub Desktop.
Save luuizeduardo/2407a2969cec12485ed69574cf5a7fee to your computer and use it in GitHub Desktop.
package org.example.repositories;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Repository;
import java.io.IOException;
import java.net.URL;
@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