无法使用 JacksonXml 将 XML 对象反序列化为数据类
我正在尝试将此 xml string: 反序列化
val xml2 = """
<id>3</id>
""".trimIndent()
到此数据类
@JacksonXmlRootElement(localName = "id")
data class Id(
// @field:JacksonXmlProperty(isAttribute = true)
// @JsonInclude(JsonInclude.Include.NON_NULL)
// val attribute: String? = null,
@JacksonXmlText
val value: Int
)
,但每次我尝试这样做时
println(JacksonXml.asA<Id>(xml2))
都会遇到此异常:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid definition for property ''
Why can I not make use of the @JacksonXmlText
注释?我的目的是弄清楚如何反序列化如下所示的 xml 字符串:
<id attribute="Pig">3</id>
但我什至无法让 @JacksonXmlText
注释单独工作,所以有没有一种解决方法可以让我不使用@JacksonXmlText 也能完成同样的事情吗?
I'm attempting to deserialize this xml string:
val xml2 = """
<id>3</id>
""".trimIndent()
to this data class
@JacksonXmlRootElement(localName = "id")
data class Id(
// @field:JacksonXmlProperty(isAttribute = true)
// @JsonInclude(JsonInclude.Include.NON_NULL)
// val attribute: String? = null,
@JacksonXmlText
val value: Int
)
but every time I attempt to do so by doing this
println(JacksonXml.asA<Id>(xml2))
I get this exception:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid definition for property ''
Why can I not make use of the @JacksonXmlText
annotation? My intention is to figure out how to deserialize xml strings that look like this:
<id attribute="Pig">3</id>
but I can't even get the @JacksonXmlText
annotation to work on its own, so is there a workaround that would allow me to accomplish the same thing without making use of @JacksonXmlText
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以试试这个样品吗?它对我有用。
Can u try this sample? it works for me.