org.http4k.format.ConfigurableJacksonYaml.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4k-format-jackson-yaml Show documentation
Show all versions of http4k-format-jackson-yaml Show documentation
Http4k YAML support using Jackson as an underlying engine
package org.http4k.format
import com.fasterxml.jackson.databind.ObjectMapper
import org.http4k.core.Body
import org.http4k.core.ContentType.Companion.TEXT_YAML
import org.http4k.lens.BiDiBodyLensSpec
import org.http4k.lens.ContentNegotiation
import org.http4k.lens.ContentNegotiation.Companion.None
import org.http4k.lens.string
import org.http4k.websocket.WsMessage
import kotlin.reflect.KClass
open class ConfigurableJacksonYaml(val mapper: ObjectMapper) : AutoMarshalling() {
override fun asA(input: String, target: KClass): T = mapper.readValue(input, target.java)
override fun asFormatString(input: Any): String = mapper.writeValueAsString(input)
inline fun WsMessage.Companion.auto() = WsMessage.string().map(mapper.read(), mapper.write())
inline fun Body.Companion.auto(description: String? = null, contentNegotiation: ContentNegotiation = None) = autoBody(description, contentNegotiation)
inline fun autoBody(description: String? = null, contentNegotiation: ContentNegotiation = None): BiDiBodyLensSpec = httpBodyLens(description, contentNegotiation, TEXT_YAML).map(mapper.read(), mapper.write())
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy