事例:
@JacksonXmlRootElement(localName = "xml")
public class XmlResult {
@JacksonXmlProperty(localName = "InfoType")
private String infoType;
}
引入包
<!-- jackson序列化反序列化xml数据格式 -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
调用
ObjectMapper mapper = new XmlMapper();
//忽略实体类中不含有的字段方法
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//xmlString为需要解析的xml字符串,XmlResult 为使用了注解的DTO类
XmlResult xmlResult = mapper.readValue(xmlString, XmlResult.class);