XML 字符串 转 JSON
2021-06-16 14:03
标签:别名 drive pack 识别 imp on() oda 1.2 oid package com.yile.test; import com.google.gson.Gson; public class XStreamTest { XStream xstream = new XStream(new DomDriver()); //设置了这个别名才能识别下面 xml 中的 product 节点,否则要用类全限名称 JARS: cglib-nodep-3.2.5.jar XML 字符串 转 JSON 标签:别名 drive pack 识别 imp on() oda 1.2 oid 原文地址:http://www.cnblogs.com/Lennyyi/p/7271441.html
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.yile.model.Product;
public static void main(String[] args) {
xstream.alias("product", Product.class);
String xml = "
"
Product prod = (Product)xstream.fromXML(xml);
Gson gson = new Gson();
String proStr = gson.toJson(prod);
System.out.println(proStr);
}
}
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