I have a json file that contains static data and i want to create a springboot service that returns the content of that file. Thus far i have managed to just connect to the file but im not sure how to return the json data.
This is the json:
{
"carrots": [ 1, 2, 5, 10, 12.5, 20, 50 ],
"apple": [ 100, 500, 750, 900 ],
"orange": [200, 500, 1000],
"lemon": [1, 2, 5, 10, 20, 25],
"peanuts": [200, 500, 1000]
}
This is some schedo code to what i am trying to achieve :
public JsonInformationHereAsReturnType getJsonContent() {
File file = ResourceUtils.getFile("classpath:sample.json");
//Read File Content
String content = new String(Files.readAllBytes(file.toPath()));
return content;
}
After runing the code i want to just get back the same json i.e
{
"carrots": [ 1, 2, 5, 10, 12.5, 20, 50 ],
"apple": [ 100, 500, 750, 900 ],
"orange": [200, 500, 1000],
"lemon": [1, 2, 5, 10, 20, 25],
"peanuts": [200, 500, 1000]
}
How do i achieve this result.