private String convertObjectToXmlStr(Object object) throws Exception {

        StringWriter stringWriter = new StringWriter();

        JAXBContext jaxbContextRequest;

        try {

            jaxbContextRequest = JAXBContext.newInstance(object.getClass());

            Marshaller jaxbMarshaller = jaxbContextRequest.createMarshaller();

            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(object, stringWriter);

            String xml = stringWriter.toString();

            return xml;

        } catch (JAXBException e) {

            logger.error("convertObjectToXmlStr faild. cause : " + e.getMessage());


        }

    }

+ Recent posts