Suppose I have an Employee Class which has a reference of another class say address which has its own attributes. So please let me know how to convert that into xml file and also the vice versa of it.
Thanks!!
Suppose I have an Employee Class which has a reference of another class say address which has its own attributes. So please let me know how to convert that into xml file and also the vice versa of it.
Thanks!!
JAXB
- It will help you to convert Object to XML and XML to Object. https://jaxb.java.net/
The easiest way is to use the JAXB
class that is part of the standard library.
Java Object => XML
JAXB.marshal(yourObject, new File("obj.xml"));
XML => Java object
YourClass yourObject = JAXB.unmarshal(new File("obj.xml"), YourClass.class);
You can customize the serialization/deserialization with annotation on the class and on its fields.