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 "\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); // } // }; // } }