Revision: 65275
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 14, 2013 03:25 by lucaborace
Initial Code
private static void printJaxbObject(
Object jaxbObject) {
JAXBContext jaxbContext;
try {
jaxbContext = JAXBContext.newInstance(jaxbObject.getClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
String namespace = "";
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);
jaxbMarshaller.marshal(r, System.out);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Initial URL
Initial Description
Method to print on System Out a JAXB annotated object
Initial Title
Print JAXB Annotated Object
Initial Tags
Initial Language
Java