java
jaxb sample code
기계새
2014. 3. 17. 17:36
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());
}
}