I want to return json response something like this in spring boot :
{
"status" : true,
"message" : "Data is found",
"data" : single object or list of object
}
My RestController look like this
@GetMapping("/users")
public JSONObject getAllUsers() {
List<User> user = repository.findAll(); // get all users from db
JSONObject jsonObject = new JSONObject();
jsonObject.put("status", true);
jsonObject.put("message", "Data is found");
jsonObject.put("data", user);
return jsonObject;
}
But I am getting response something like this
{
"empty": false
}
So, how can I return json reponse in the format like I mentioned above ?