标签:别名 drive pack 识别 imp on() oda 1.2 oid
package com.yile.test;
import com.google.gson.Gson;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.yile.model.Product;
public class XStreamTest {
public static void main(String[] args) {
XStream xstream = new XStream(new DomDriver());
//设置了这个别名才能识别下面 xml 中的 product 节点,否则要用类全限名称
xstream.alias("product", Product.class);
String xml = "<product><prodId>1001</prodId><prodName>电脑" +
"</prodName><prodPrice>4000.0</prodPrice></product>";
Product prod = (Product)xstream.fromXML(xml);
Gson gson = new Gson();
String proStr = gson.toJson(prod);
System.out.println(proStr);
}
}
JARS:
cglib-nodep-3.2.5.jar
dom4j-1.6.1.jar
gson-2.8.1.jar
jdom-2.0.2.jar
jdom2-2.0.6.jar
jettison-1.3.8.jar
joda-time-2.9.9.jar
kxml2-2.3.0.jar
kxml2-min-2.3.0.jar
stax-api-1.0-2.jar
woodstox-core-asl-4.4.1.jar
xmlpull-1.1.3.1.jar
xom-1.2.10.jar
xpp3_min-1.1.4c.jar
xstream-1.4.10.jar
标签:别名 drive pack 识别 imp on() oda 1.2 oid
原文地址:http://www.cnblogs.com/Lennyyi/p/7271441.html