This may be dumb question but I am unable to find the answer while looking through documentation for java REST API. My question is that I want to name the REST array JSON api response and format it with a name.
for example below is the response from my REST API being pulled from my backend.
current API response
[
{
"categoryName": "Hardware",
"categoryId": 1
},
{
"categoryName": "Software",
"categoryId": 2
}
]
desired API response
"categories": [
{
"categoryName": "Hardware",
"categoryId": 1
},
{
"categoryName": "Software",
"categoryId": 2
}
]
controller
@RequestMapping(method = RequestMethod.GET,)
@ResponseBody
public List<Category>findAllCategories() {
return categoryRepository.findAll();
}
model
private String categoryName;
private int categoryId;
**getters/setters**