JSON против XML и немного рефакторинга. Приложение 2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package ru.golodnyj.lection.json;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
import com.thoughtworks.xstream.XStream;
/**
* Date: 26.08.2009
* Time: 7:25:40
*
* @author golodnyj
* @version 0.1
*/
public class ConsoleJSON {
public static void main(String[] args) {
Client c = new Client("name",true , 5);
// Создание XML
XStream xstream = new XStream(new DomDriver());
//xstream.alias("client", Client.class);
String xml = xstream.toXML(c);
System.out.println("xml "+ xml.length() +" : \n" + xml);
// Создание JSON
XStream xstream1 = new XStream(new JsonHierarchicalStreamDriver());
//XStream xstream1 = new XStream(new JettisonMappedXmlDriver());
//xstream1.alias("client", Client.class);
String json = xstream1.toXML(c);
System.out.println("json "+ json.length() +" : \n" + json);
}
}