I'm using a JSON file with thousands of rows (that serves as a "database"). It is being deserialized and then the logic of the app is based on deserialized pojos.
I'd like to enable user to switch these JSON files before running the app in the command line: (e.g.)
java -jar target/app.jar -source=resources/data.json
The app is built with Spring Boot and I've been reading files like that:
file = ResourceUtils.getFile("/Users/App/src/main/resources/data.json");
I've found some instructions about loading properties, but what i would like to do is to load a whole file and I can't seem to find a reliable instruction.
Edit:
application.properties:
source = filepath
fragment of my DAO:
@Repository
public class SomethingDao {
private ObjectMapper mapper = new ObjectMapper();
private File file;
@Value("${source}")
private String source;
{
try {
file = ResourceUtils.getFile(source);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
something = mapper.readValue(file, Something.class);
} catch (IOException e) {
e.printStackTrace();
}
}
commands i tried to use:
java -jar target/app.jar -source="src/main/resources/data.json"
java -jar target/app.jar -source="/data.json"
java -jar target/app.jar --source="src/main/resources/data.json"
java -jar target/app.jar --source="/data.json"
and so on...