With the inspiration/idea from JacksonXmlRootElement with dynamic localName value, I used the interface based solution.
I declared the main (data) class Root
, which I did not annotate with @JacksonXmlRootElement
. Then declared two interfaces, Root1
and Root2
with both @JacksonXmlRootElement
and made Root
to implement them both.
The solution in Kotlin would be:
@JacksonXmlRootElement(localName = "root1")
interface Root1
@JacksonXmlRootElement(localName = "root2")
interface Root2
data class Root(
@field:JacksonXmlProperty(localName = "a") val a: String,
@field:JacksonXmlProperty(localName = "b") val b: String,
@field:JacksonXmlProperty(localName = "c") val c: String
): Root1, Root2