Hi All,
I'm currently using @ResponseBody to return some JSON data for a number of REST calls. One of the calls does return a list of enums which is also automatically converted to JSON:
Controller
My Enum looks as follows:Code:@Controller @RequestMapping("/test") public class RestController { /** * Register all binder for custom data types so these types * can be extracted from incoming requests and values assigned * to objects. * @param binder */ @InitBinder public void initAllBinder(WebDataBinder binder) { // register handler for dates binder.registerCustomEditor(Date.class, new DatePropertyEditor()); // register binder for report types binder.registerCustomEditor(ReportTypeEnum.class, new ReportTypePropertyEditor()); } /** * Method to return the list of report types * @param request * @param response * @return */ @RequestMapping(value = "/findReportTypes", method = RequestMethod.GET) public @ResponseBody List<ReportTypeEnum> findReportTypes(HttpServletRequest request, HttpServletResponse response) { try { // ... return my List<ReportTypeEnum> } catch (RESTException e) { // ... do some error handling } return retVal; } // ... }
The JSON response currently only contains the ReportTypeEnum.name value. How can I have more control over what's actually being returned to the requestor? I'd like not only to return the ReportTypeEnum.name, but also the reportFullName.Code:public enum ReportTypeEnum { SUMMARY("Summary Report"), YEAR("Year end Report"); // name of the report private String reportFullName; private ReportTypeEnum(String fname) { this.reportFullName = fname; } // .... }
Thanks in advance,
Daniel


Reply With Quote