`

com.thoughtworks.xstream.XStream的使用注意

阅读更多
最近在搞微信开发,遇到一个问题,记录下来解决办法与大家分享。

在引用XStream这个类的时候代码:

public static XStream createXstream() {
return new XStream(new XppDriver() {
@Override
public HierarchicalStreamWriter createWriter(Writer out) {
return new PrettyPrintWriter(out) {
boolean cdata = false;
Class<?> targetClass = null;


@Override
public void startNode(String name,
@SuppressWarnings("rawtypes") Class clazz) {
super.startNode(name, clazz);
// 业务处理,对于用XStreamCDATA标记的Field,需要加上CDATA标签
if (!name.equals("xml")) {
cdata = needCDATA(targetClass, name);
} else {
targetClass = clazz;
}
}


@Override
protected void writeText(QuickWriter writer, String text) {
if (cdata) {
writer.write("<![CDATA[");
writer.write(text);
writer.write("]]>");
} else {
writer.write(text);
}
}
};
}
});
}

在当前类的第一行(package位置)会提示:Multiple markers at this line

- The type org.xmlpull.v1.XmlPullParser cannot be resolved. It is indirectly referenced from required .class files
- The type org.xmlpull.v1.XmlPullParser cannot be resolved. It is indirectly referenced from required .class files
- The type org.xmlpull.v1.XmlPullParserException cannot be resolved. It is indirectly referenced from
required .class files

这样的信息,这是因为XStream只是一个jar文件,但是它里面会依赖一个jar包,依赖的jar包是:xmlpull_1_0_5.jar、只要把这个jar包引入之后,问题即可解决!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics