Notes on the use of com.thoughtworks.xstream.XStream

Recently I was working on WeChat development and encountered a problem. I recorded the solution and shared it with you.

When referring to the XStream class, the code:

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);
// For business processing, for Field marked with XStreamCDATA, a CDATA tag needs to be added
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);
}
}
};
}
});
}

In the first line of the current class (package position), it will prompt: 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

, this is because XStream is just a jar file , but it will depend on a jar package. The dependent jar package is: xmlpull_1_0_5.jar. As long as this jar package is introduced, the problem can be solved!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327007962&siteId=291194637