标签使用
- @JacksonXmlRootElement(localName = “Class”)
xml 根元素名称
- @JacksonXmlElementWrapper(localName = “Students”)
列表的包装标签
- @JacksonXmlProperty(localName = “Stu”)
xml 属性,默认节点方式。@JacksonXmlProperty(isAttribute = true, localName = "Stu") 设置为xml属性的表现形式。
- @JacksonXmlText
表现形式为xml中的文本节点。
XML 转换设置
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.setDefaultUseWrapper(false);
//字段为null,自动忽略,不再序列化
//XML标签名:使用骆驼命名的属性名,
xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
//设置转换模式
xmlMapper.enable(MapperFeature.USE_STD_BEAN_NAMING);
注意
节点和text文本不能混用。例如下面在fastxml中不被支持。
<Turn id="S2" startTime="10.86" endTime="30.02">
<Sync time="10.86"/>
Some text here
</Turn>
https://stackoverflow.com/questions/52943396/jackson-xml-null-jacksonxmltext-property
https://blog.csdn.net/u014746965/article/details/78647616
https://github.com/FasterXML/jackson-dataformat-xml/wiki/Jackson-XML-annotations