// 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.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;

public class JSON {
    public static void main(String[] args) throws IOException {
        Data o = new Data(123, "ABC");
        System.out.println(o);
        StringWriter sw = new StringWriter();
        XStream xstream = new XStream(new JettisonMappedXmlDriver());
        xstream.toXML(o, sw);
        sw.close();
        String s = sw.toString();
        System.out.println(s);
        StringReader sr = new StringReader(s);
        XStream xstream2 = new XStream(new JettisonMappedXmlDriver());
        Data o2 = (Data)xstream2.fromXML(sr);
        sr.close();
        System.out.println(o2);
    }
}

class Data {
    private int iv;
    private String sv;
    public Data() {
        this(0, "");
    }
    public Data(int iv, String sv) {
        this.iv = iv;
        this.sv = sv;
    }
    public int getIv() {
        return iv;
    }
    public void setIv(int iv) {
        this.iv = iv;
    }
    public String getSv() {
        return sv;
    }
    public void setSv(String sv) {
        this.sv = sv;
    }
    public String toString() {
        return "[" + iv + "," + sv + "]";
    }
}
