This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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