Thursday, 20 March 2014

Jaxb object to xml convertion

//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;
}

No comments:

Post a Comment

Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...