// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;

public class XmlSer {
    public static void main(String[] args) {
        ArrayList<Data> lst = new ArrayList<Data>();
        lst.add(new Data(1, "A"));
        lst.add(new Data(2, "BB"));
        lst.add(new Data(3, "CCC"));
        System.out.println(lst);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLEncoder xe = new XMLEncoder(baos);
        xe.writeObject(lst);
        xe.close();
        byte[] b = baos.toByteArray();
        System.out.println(new String(b));
        ByteArrayInputStream bais = new ByteArrayInputStream(b);
        XMLDecoder xd = new XMLDecoder(bais);
        @SuppressWarnings("unchecked")
        ArrayList<Data> newlst = (ArrayList<Data>)xd.readObject();
        System.out.println(newlst);
    }
}
