I have an XML Sttructure and want to Deserialize this to an Object with a Property Description as a Plain HTML-String
<ItemList>
<Item ID="1">
<Description>
<p>
<span>This is a HTML Description</span>
</p>
<p>
With undefined number of subnodes
</p>
</Description>
</Item>
<Item ID="2">
<Description>
<p>
<span>This is a HTML Description</span>
</p>
<ul>
<li>Some Other Nodes</li>
</ul>
</Description>
</Item>
</ItemList>
The description tag contains only HTML text and i don't want to define classes for all possible HTML-Tags. Is there a solution, for example with a custom Deserializer, to parse the Tags inside Description as Plain Html-Text?
My classes look like this
data class ItemList(
@JacksonXmlProperty(localName = "Item")
@JacksonXmlElementWrapper(useWrapping = false)
val items: List<Item> = listOf()
)
data class Item(
@JacksonXmlProperty(localName = "ID", isAttribute = true)
val id: String? = null,
@JacksonXmlProperty(localName = "Description")
val description: HtmlText? = null
)
data class HtmlText(
val text: String? // This should be the Plain HTML-String
)
private val xmlMapper = XmlMapper()
.registerKotlinModule()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
val itemlist = xmlMapper.readValue<ItemList>(stream) // stream is the XML file described above