标签:void print default ring sys add 需求 out 解析xml
public interface XmlResolver<T> {
XStream builder();
default T parse(String xml){
return (T) builder().fromXML(xml);
}
default T resolver(String xml){
return parse(xml);
}
}
//测试类
public class TestMain {
private String name;
private String address;
private List<TestPerson> personList;
public static void main(String[] args) {
XmlResolver<TestMain> testMainXmlResolver = () -> {
{
XStream xStream = new XStream();
xStream.alias("GetInvoiceResult", TestMain.class);
xStream.alias("ItemRecord", TestPerson.class);
return xStream;
}
};
String xml = "<GetInvoiceResult>\n" +
" <name>string</name>\n" +
" <address>string</address>\n" +
" <personList>\n" +
" <ItemRecord>\n" +
" <name>string</name>\n" +
" <age>string</age>\n" +
" </ItemRecord>\n" +
" <ItemRecord>\n" +
" <name>string</name>\n" +
" <age>string</age>\n" +
" </ItemRecord>\n" +
" </personList>\n" +
" </GetInvoiceResult>\n"
;
TestMain testMain = testMainXmlResolver.parse(xml);
System.out.println(testMain);
}
}
标签:void print default ring sys add 需求 out 解析xml
原文地址:https://www.cnblogs.com/canmeng-cn/p/8849001.html