f-angi
7/20/2017 - 9:58 AM

Given a class bound to an xml, it prints the corresponding xml

Given a class bound to an xml, it prints the corresponding xml

private String marshalToXml(MsgLoadInType msgLoadInType)
        throws JAXBException {

    StringWriter stringWriter = new StringWriter();

    JAXBContext jaxbContext = JAXBContext.newInstance(MsgLoadInType.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    // format the XML output
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    QName qName = new QName("it.intesys.arag.portlet.denuncia", "msgLoadInType");
    JAXBElement<MsgLoadInType> root = new JAXBElement<>(qName, MsgLoadInType.class, msgLoadInType);

    jaxbMarshaller.marshal(root, stringWriter);

    return stringWriter.toString();
}