实体类 属性 转换为 XML
作者:互联网
@XStreamAlias(“ToUserName”) 属性别名
//在被转换的实体类上加注解
@XStreamAlias(“xml”)//根节点名 实体类全限定类名修改为自定义名
//使用 xStream 把对象转换为 xml
TextMessage message = new TextMessage(map, "你好");
XStream xStream = new XStream();
xStream.processAnnotations(TextMessage.class); //如果修改根节点名
String user = xStream.toXML(message); //转换
System.out.println(user);
<!--对象转换为XML-->
<!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.14</version>
</dependency>
标签:XML,实体类,转换,xStream,TextMessage,message,xstream,属性 来源: https://blog.csdn.net/weixin_48921808/article/details/111441365