Hello,
I am having some trouble passing a Java List of type "Item" (i.e. my own class) to XML for my web services. Basically, I have specific handler methods that deal with content-type: application/xml and text/html. However, when I am using an HTTP GET from a test client, I am issuing ACCEPT: application/xml and expecting the returned resource in XML.
I am using Spring and My handler method is given below:
Code:// One of the handlers @RequestMapping(value = "/items", method = RequestMethod.GET, headers = "accept=application/xml") @ResponseBody public List<Item> getAllItems(HttpServletRequest request, HttpServletResponse response) { if (request == null) { throw new IllegalArgumentException(NULL_REQ); } List<Item> items = ItemDaoJpa.findAllItems(); audit.record( this.getClass(), "REST", "Served request (" + request.getRemoteAddr() + "): " + items.toString()); return items; }when I am issuing a GET from my HTTP Client with Header = Accept: application/xml, it breaks down and returns a 406. I know that Spring has a default marshaller working underneath and doing all sorts of magic. I can see MyType object converted into xml as it had an @XmlRootElement annotation in the class definition. But I am not sure if I need to do anything extra to display a List<Item> in XML viewCode:// Another handler method @RequestMapping(value = "/items", method = RequestMethod.GET, headers = "accept=text/html") public String showAdmin( HttpServletRequest request, HttpServletResponse response, ModelMap model, @RequestParam(value = "domainId", defaultValue = "") String domainId, @RequestParam(value = "nhsNo", defaultValue = "") String nhsNo, @RequestParam(value = "date", defaultValue = "") String timeStamp, @RequestParam(value = "tags", defaultValue = "") String tags, @RequestParam(value = "data", defaultValue = "101010212012020120122020") byte[] sdsData) { model.addAttribute("listAllItems", ItemDaoJpa.findAlltems()); model.addAttribute("editBoxDomainId", domainId); model.addAttribute("editBoxNhsNo", nhsNo); model.addAttribute("editBoxDate", timeStamp); model.addAttribute("editBoxTags", tags); model.addAttribute("editBoxdata", data); return "items"; }
N.B. I currently have no marshaller specified explicitly in the dependency section for my POM file and I am using Maven with SPring.
Could anyone help me please ?


Reply With Quote
