jen20
11/05/2017, 10:27 PMimport com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
data class MyThing(
@JacksonXmlProperty(isAttribute = true)
val name: String,
@JacksonXmlProperty(isAttribute = true, localName = "years")
val age: Int
)
fun main(args: Array<String>) {
val mapper = XmlMapper().registerModule(KotlinModule())
val xml = """<MyThing name="Test" years="10" />"""
val thing: MyThing = mapper.readValue(xml)
println(thing)
}