private String obj2xml(Object obj) { try { JAXBContext context = JAXBContext.newInstance(CFX.class);// CXF是xml主实体对象 Marshaller marshaller = context.createMarshaller(); // 设置编码格式 marshaller.setProperty(Marshaller.JAXB_ENCODING, "GBK"); // 去掉生成的默认报文头 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter writer = new StringWriter(); writer.append(SFIConstantEnum.SFI_XML_ATTR); // SFI_XML_ATTR = "<?xml version=\"1.0\" encoding=\"GBK\"?>" marshaller.marshal(obj, writer); return writer.toString(); } catch (Exception e) { Logger.error(this, SFICommonUtils.getShowLineMessage("实体转换xml异常"), e); throw new SFIServiceException("实体转换xml异常"); } }