考虑一个简单的Xsctream示例来创建Bean的JSON:
Bean bean = new Bean();
bean.addNames("John", "Doe");
bean.addNames("Jane", "Doe");
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.setMode(XStream.NO_REFERENCES);
System.out.println(xstream.toXML(bean));
结果
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/Configuration
at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.<init>(JettisonMappedXmlDriver.java:55)
at Main.main(Main.java:12)
请注意库已导入,因为它们应该
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
包括适当的罐子