I am using spring mvc with org.springframework.web.servlet.view.json.MappingJackson2JsonView to return json objects from controllers, To integrate with ember RestAdapter I need to return the json with namespace on it. How do I do that ? Currently I have the following controller which returns an Object (JSON) which can be a list of Customer Ids or List of Customer Objects,
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public Object getCustomer(HttpServletRequest request, HttpServletResponse response) {
if (request.getQueryString()!=null){
List<Integer> customerIdList = new ArrayList<Integer>();
customerIdList = customerDao.findAllCustomerIds();
return customerIdList;
} else {
List<Customer> customerList = new ArrayList<Customer>();
customerList = customerDao.findAllCustomers();
return customerList ;
}
}
The output I get is,
If I include a query string,
[ 1,2,3 ]
else
[ {
id: "1",
name: "ABC Pty Ltd"
},
{
id: "2",
name: "XYZ Ltd"
},
{
id: "3",
name: "Hello "
}
]
The result I want is,
if I include query string,
{ customers : [ 1,2,3 ] };
else
{ customers : [
{
id: "1",
name: "ABC Pty Ltd"
},
{
id: "2",
name: "XYZ Ltd"
},
{
id: "3",
name: "Hello "
}
]
}
How can I achieve this ?