/ Published in: Java

Method to print on System Out a JAXB annotated object
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private static void printJaxbObject( JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(jaxbObject.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); if(jaxbObject.getClass().getPackage().isAnnotationPresent(javax.xml.bind.annotation.XmlSchema.class)) { javax.xml.bind.annotation.XmlSchema schema = jaxbObject.getClass().getPackage().getAnnotation(javax.xml.bind.annotation.XmlSchema.class); namespace = schema.namespace(); } // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); JAXBElement<?> r = new JAXBElement(new QName(namespace, jaxbObject.getClass().getSimpleName()), jaxbObject.getClass(), jaxbObject); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Comments
