'Cannot deserialize XML object to data class using JacksonXml
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
?
Solution 1:[1]
Can u try this sample? it works for me.
@JacksonXmlRootElement(localName = "id")
data class Id(
//Your fields
) {
@JacksonXmlText
val value: Int? = 0
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Having Fun |