I have Class A. Class B and Class C are part of Class A.
Class A
{
//Few Properties of Class A
List list1 = new List()
JAXB is the best I ever used.
http://www.oracle.com/technetwork/articles/javase/index-140168.html
From XML:
QuestionEntity obj = null;
try {
JAXBContext ctx = JAXBContext.newInstance(QuestionEntity.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
obj = (QuestionEntity) unmarshaller.unmarshal(new StreamSource(new StringReader(xml)));
} catch (JAXBException e) {
e.printStackTrace();
}
To XML:
JAXBContext ctx = JAXBContext.newInstance(TestEntity.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
StringWriter stringWriter = new StringWriter();
marshaller.marshal(this, stringWriter);
return stringWriter.toString();