We showed how to transform xml to java hashmap with xstream in this example will show how to convert xml to a java arraylist and arraylist to xml using xstream. XStream is a java library to convert Java Objects into XML and then back again. The set up will create a POJO Funeral object, an arraylist funerals and initialize the arraylist with some set up data.
Setup
Serialize arraylist to xml
Using the funerals list we will marshal it to xml. Initializing XStream object, a simple facade to the xstream library, we will call toXML passing in the arraylist which will convert the object to xml where will pretty print xml as a string.
Output
Deserialize xml to java arraylist
Taking the xml output above we will unmarshall or deserialize the xml into a java arraylist. As above we will create an XStream object and call fromXML passing in the sample xml.