Reputation: 271
I am getting the below error during the evaluation of the freemarker. However, this error only shows up only in the builds, not in IDE.
{"code":"NoApplicableCode","description":"Error occured processing template freemarkerTest.ftl\nThe following has evaluated to null or missing:\n==> loadJSON
//freemarker function
<#assign keywordsJSON = "${loadJSON('path/to/file/random.json')}">
//function for creating freemarker function
protected void addUtilityFunctions(String baseURL, Map<String, Object> model) {
model.put("loadJSON", parseJSON());
}
private TemplateMethodModelEx parseJSON() {
return arguments -> loadJSON(arguments.get(0).toString());
}
private String loadJSON(String filePath) {
JSONParser parser = new JSONParser();
try {
File file = fileFinder.findFile(filePath);
if (file == null) {
LOGGER.warning("File is outside of data directory");
throw new RuntimeException(
"File " + filePath + " is outside of the data directory");
}
return parser.parse(new FileReader(file.getPath())).toString();
} catch (Exception e) {
LOGGER.warning("Failed to parse JSON file " + e.getLocalizedMessage());
}
LOGGER.warning("Failed to create a JSON object");
return "Failed to create a JSON object";
}
Upvotes: 0
Views: 1954
Reputation: 271
The problem was there were different functions for different freemarker templates. I did not put the function to the correct place. All syntax and the function calling is true in the question.
Upvotes: 0