org.http4k.format.ConfgurableJacksonXml.kt Maven / Gradle / Ivy
package org.http4k.format
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import java.io.InputStream
import kotlin.reflect.KClass
open class ConfigurableJacksonXml(private val mapper: XmlMapper) : AutoMarshallingXml() {
override fun Any.asXmlString(): String = mapper.writeValueAsString(this)
override fun asA(input: String, target: KClass): T = mapper.readValue(input, target.java)
override fun asA(input: InputStream, target: KClass): T = mapper.readValue(input, target.java)
}
fun KotlinModule.asConfigurableXml() = asConfigurable(
XmlMapper(JacksonXmlModule().apply { setDefaultUseWrapper(false) })
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy