XStream-bean変換xml Yes、CDATAを携帯
1442 ワード
XStream :https://blog.csdn.net/fz13768884254/article/details/83012232
XStream :
pom依存性:
xstream
xstream
1.2.2
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.core.util.QuickWriter;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
import com.thoughtworks.xstream.io.xml.XppDriver;
import java.io.Writer;
public class XStreamUtil {
private static String PREFIX_CDATA = "";
/**
*
*/
public static XStream initXStream() {
return new XStream(new XppDriver() {
@Override
public HierarchicalStreamWriter createWriter(Writer out) {
return new PrettyPrintWriter(out) {
protected void writeText(QuickWriter writer, String text) {
// if (text.startsWith(PREFIX_CDATA) &&
// text.endsWith(SUFFIX_CDATA)) {
writer.write(PREFIX_CDATA + text + SUFFIX_CDATA);
// } else {
// super.writeText(writer, text);
// }
}
};
}
});
}
}