2018-06-19 19:56:54 +08:00

58 lines
1.4 KiB
Java

package com.tenwa.sdk.utils;
import java.io.OutputStream;
import java.io.Writer;
import com.thoughtworks.xstream.XStream;
public class XMLStream extends XStream {
// XML的声明
public String getDeclaration() {
return "<?xml version=\"1.0\" encoding=\"GBK\"?>\n";
}
@Override
public void toXML(Object obj, OutputStream output) {
try {
String dec = this.getDeclaration();
byte[] bytesOfDec = dec.getBytes("UTF-8");
output.write(bytesOfDec);
} catch (Exception e) {
throw new RuntimeException("error", e);
}
super.toXML(obj, output);
}
@Override
public void toXML(Object obj, Writer writer) {
try {
writer.write(getDeclaration());
} catch (Exception e) {
throw new RuntimeException("error", e);
}
super.toXML(obj, writer);
}
// @Override
// protected MapperWrapper wrapMapper(MapperWrapper next) {
// return new MapperWrapper(next) {
// @Override
// public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") Class definedIn, String fieldName) {
// // 不能识别的节点,掠过。
// if (definedIn == Object.class) {
// return false;
// }
// // 节点名称为fileName的掠过
// if (fieldName.equals("dcPayReqxList")) {
// return false;
// }
// return super.shouldSerializeMember(definedIn, fieldName);
// }
// };
// }
}