java - 具有属性 AND 值的 xml 反序列化
问题描述
我对 XML 的反序列化有点麻烦。我只能通过以下方式反序列化此 xml:
@JacksonXmlProperty(localName = "field")
@JacksonXmlElementWrapper(useWrapping = false)
List<Object> field;
这是我的xml:
<Response>
<user>
<field attribute="x"></field>
<field attribute="y">false</field>
<field attribute="z">string</field>
</user>
<user>
<field attribute="x"></field>
<field attribute="y">false</field>
<field attribute="z">string</field>
</user>
</Response>
问题是,我想用一些特定的类替换Object
in ,这样我就可以访问.List<Object> field;
attribute
field
有了Object
,我可以创建这样的东西:
user='[{attribute=x}, {attribute=y, =false}, {name=z, =string}]
多谢。
解决方案
找到答案。我创建了包含这些元素的新类:
@JacksonXmlProperty(isAttribute = true, localName = "attribute")
String attribute;
@JacksonXmlText
String value;
并Object
用这个新类替换。
推荐阅读
- python - 通过服务更换壁纸的问题
- bixby - 在 Bixby 模拟器中,是否可以在开发配置和生产配置之间切换?
- php - 当值为真时,PHP if else 语句不执行代码
- javascript - 如何将对象从视图传递到 ASP.NET MVC 中的控制器?
- javascript - 将输入数据从子级传递给父级 React.js
- python - 包括函数的循环,因此如果数字不正确,它可以要求用户重新输入数字
- swift5 - WooCommerce Rest API JSON formate Complex implementation in Swift
- react-final-form - 当使用 react-final-form 从表单数组中删除元素时,显示的值不会更新,但最终形式的数据对象会
- machine-learning - CFG : Every rule in a context-free grammar is of the form: A->B, What do A and B represent?
- gitlab - Git Lab CI/CD for web app running in windows serer(VM) IIS