package com.zy.common.webservice.mock;
|
|
|
import com.alibaba.fastjson.JSON;
|
import com.zy.common.utils.XmlUtils;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* Created by vincent on 2021/7/13
|
*/
|
public class XmlMock {
|
|
public static void main(String[] args) {
|
Demo demo = new Demo(1, "Steven", "@sun123", new Date(), 1000.0);
|
List<Computer> list = new ArrayList<Computer>();
|
list.add(new Computer("xxxMMeedd", "asus", new Date(), 4455.5));
|
list.add(new Computer("lenvoXx", "lenvo", new Date(), 4999));
|
demo.setComputers(list);
|
System.out.println("---将对象转换成xml Start---");
|
String xml = XmlUtils.objToXml(demo);
|
System.out.println(xml);
|
System.out.println("---将对象转换成File类型的xml End---");
|
System.out.println();
|
System.out.println("---将xml转换成对象 Start---");
|
Demo demo1 = (Demo) XmlUtils.xmlToObj(Demo.class, xml);
|
System.out.println(JSON.toJSONString(demo1));
|
System.out.println("---将File类型的xml转换成对象 End---");
|
|
}
|
|
|
}
|