Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

It’s pretty hard to troubleshoot generated XML. JAXB offers the ability to output it’s generated XML with a formatted option. After you create the marshaller but before you marshall, tell the marshaller to output formatted xml by:

JAXBContext jaxbContext = JAXBContext.newInstance(Animal.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter stringWriter = new StringWriter();
marshaller.marshal(watchForm, stringWriter);

August 21st, 2012

Posted In: Java, JAXB, xml

Leave a Reply

Your email address will not be published. Required fields are marked *

LinkedIn Auto Publish Powered By : XYZScripts.com