this is my first time building a Jersey Restful web service.
The project is supposed to be a server that provides information about Reddit posts. For now, this information is stored in a large JSON file, and because it is not supposed to be manipulated, my idea is to store this information in the dao class in form of Post instances.
here is my projects' folder organisation: filesView
So my idea is to populate the dao class by reading the json file something like this:
public enum PostDao {
instance;
private Map<String, Post> posts = new HashMap<String, Post>();
private PostDao() {
//JSON parser object to parse read file
System.out.println("init");
JSONParser jsonParser = new JSONParser();
try {
FileReader reader = new FileReader("src/main/resources/data/posts.json");
//Read JSON file
Object obj = jsonParser.parse(reader);
JSONArray postsArr = (JSONArray) obj;
for (Object p : postsArr) {
JSONObject post = (JSONObject) p;
Post pobj = new Post(post.get("title"), post.get("author"));
posts.put(pobj.getId(), pobj);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
public Map<String, Post> getModel() {
return posts;
}
The problem is that I do not know where to put the json file and what the path would be.
Is there a standard folder and path to store this kind of files? Or is there a different way to populate the dao class?