I am writing an application using Spring and Rstful webservices.
I want the JSOn in the format
{companies : [{name:"companyName", industry : "companyIndustry"} ,
{name:"companyName", industry : "companyIndustry"}, ]}
But when i fire the url am getting JSON in a different format
{
companies: [5]
0: {
companyName: "Uber"
industry: "Transportation"
}-
1: {
companyName: "CVS"
industry: "Pharmacy"
}-
2: {
companyName: "Orange"
industry: "Telecom"
}-
3: {
companyName: "BostonDynamics"
industry: "Robotics"
}-
4: {
companyName: "Tesla"
industry: "Transportation"
}-
-
}
My Code
@RestController
public class CompanyController {
public static final Company companiesArray[] = {
new Company("Uber", "Transportation"),
new Company("CVS", "Pharmacy"), new Company("Orange", "Telecom"),
new Company("BostonDynamics", "Robotics"),
new Company("Tesla", "Transportation") };
@RequestMapping(value = "/companies", method = RequestMethod.GET)
private Map getAllCompanies() {
Map companyMap = new HashMap<String,String>();
companyMap.put("companies", companiesArray);
return companyMap;
}
}
where Company object has two String fields for companyName and industry.
How can I modify it to get the JSON in desired format ?