I am using jaxb marshal to convert java object to xml. My convert method looks like this:
protected String marshallerEx(Tickets tickets) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(Tickets.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
// Marshal the tickets list in console
jaxbMarshaller.marshal(tickets, sw);
LOGGER.info("marshal -> " + sw.toString());
return sw.toString();
}
The problem here is when i print it in logs, the return is coming in proper format. for example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tickets>
<ticket>
<assignedQueueId>61</assignedQueueId>
<category>11</category>
<cause>0</cause>
<createDate>2015-08-19T13:34:18-04:00</createDate>
<customFields/>
</ticket>
</tickets>
but when i return it to be displayed on screen(in browser) from my controller, it shows like this:
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<tickets>\n <ticket>\n <assignedQueueId>61</assignedQueueId>\n <category>11</category>\n <cause>0</cause>\n <createDate>2015-08-19T13:34:18-04:00</createDate>\n <customFields/>\n </ticket>\n</tickets>\n"
why is it changing the format? what do i need to do to keep the format maintained to display it on screen the same way as its in my logs?