//Pass the object class which should be converted to xml and pass base xml class to JAXBContext
public static String convertObjectToXML(GetResponse object) throws JAXBException {
String sl_XML =null;
StringWriter stringWriter = new StringWriter();
try {
JAXBContext jaxbContext = JAXBContext
.newInstance(GetResponse.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(object, stringWriter);
} catch (JAXBException e) {
throw new JAXBException(e);
}
sl_XML = stringWriter.getBuffer().toString();
return sl_XML;
}
public static String convertObjectToXML(GetResponse object) throws JAXBException {
String sl_XML =null;
StringWriter stringWriter = new StringWriter();
try {
JAXBContext jaxbContext = JAXBContext
.newInstance(GetResponse.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(object, stringWriter);
} catch (JAXBException e) {
throw new JAXBException(e);
}
sl_XML = stringWriter.getBuffer().toString();
return sl_XML;
}
No comments:
Post a Comment