public static void main(String[] args) throws Exception {
XnServiceGetUserRequest xnServiceGetUserRequest = new XnServiceGetUserRequest(); xnServiceGetUserRequest.setOPTYPE("www");
xnServiceGetUserRequest.setPERNR("eeeeeeee");
xnServiceGetUserRequest.setToken("yyyyyyy"); // 对象转xml
System.out.println(XmlUtils.xmlMapper.writeValueAsString(xnServiceGetUserRequest)); String xmlStr = "<XnServiceGetUserRequest><Token>yyyyyyy</Token><PERNR>eeeeeeee</PERNR><OPTYPE>www</OPTYPE></XnServiceGetUserRequest>";
// xml转对象
XnServiceGetUserRequest xntest = XmlUtils.xmlMapper.readValue(xmlStr, XnServiceGetUserRequest.class); // 打印是否转对象成功
System.out.println(XmlUtils.xmlMapper.writeValueAsString(xntest)); }
package com.cigna.hmc.groupinsurance.utils; import com.fasterxml.jackson.dataformat.xml.XmlMapper; /**
*
* @desc 采用fastxml 不使用老的codehaus
* @author josnow
* @date 2017年11月23日 下午5:01:44
* @version 1.0.0
*/
public class XmlUtils { public static final XmlMapper xmlMapper = new XmlMapper(); }