With the below code I have converted list to json but the format is as follows:
{\"GodownMaster\":[{\"pname\":\"FCI CHARLAPALLI\",\"pcode\":\"16042\"},
Change the return result from Map to List and put : retrun godown_list
So;
@RequestMapping("/getGodowns")
public @ResponseBody List
getGodownsBasedOnDistrict(@RequestParam(value="district_code") String
dist_code) {
List godown_list = new ArrayList();
String exception = null;
try
{
//getting name and codes here
godown_list = scm_service.getGodownListBesedOnDistCode(dist_code);
}catch(Exception ex)
{
ex.printStackTrace();
exception = ex.getMessage();
}
return godown_list ;
}
UPDATE
And you can return result as string and you will get what you need :
@RequestMapping("/getGodowns")
public @ResponseBody String
getGodownsBasedOnDistrict(@RequestParam(value="district_code") String
dist_code) {
List godown_list = new ArrayList();
String exception = null;
try
{
//getting name and codes here
godown_list = scm_service.getGodownListBesedOnDistCode(dist_code);
}catch(Exception ex)
{
ex.printStackTrace();
exception = ex.getMessage();
}
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
String arrayToJson = objectMapper.writeValueAsString(godown_list);
System.out.println("Convert List to JSON :");
System.out.println(arrayToJson);
return arrayToJson ;
}
The returned String is json format.