
com.fasterxml.jackson.module.kotlin.Extensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-kotlin Show documentation
Show all versions of jackson-module-kotlin Show documentation
Add-on module for Jackson (https://github.com/FasterXML/jackson/) to support
Kotlin language, specifically introspection of method/constructor parameter names,
without having to add explicit property name annotation.
package com.fasterxml.jackson.module.kotlin
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.TreeNode
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.MappingIterator
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.ObjectReader
import java.io.File
import java.io.InputStream
import java.io.Reader
import java.net.URL
fun jacksonObjectMapper(): ObjectMapper = ObjectMapper().registerKotlinModule()
fun ObjectMapper.registerKotlinModule(): ObjectMapper = this.registerModule(KotlinModule())
inline fun ObjectMapper.readValue(jp: JsonParser): T = readValue(jp, object: TypeReference() {})
inline fun ObjectMapper.readValues(jp: JsonParser): MappingIterator = readValues(jp, object: TypeReference() {})
inline fun ObjectMapper.readValue(src: File): T = readValue(src, object: TypeReference() {})
inline fun ObjectMapper.readValue(src: URL): T = readValue(src, object: TypeReference() {})
inline fun ObjectMapper.readValue(content: String): T = readValue(content, object: TypeReference() {})
inline fun ObjectMapper.readValue(src: Reader): T = readValue(src, object: TypeReference() {})
inline fun ObjectMapper.readValue(src: InputStream): T = readValue(src, object: TypeReference() {})
inline fun ObjectMapper.readValue(src: ByteArray): T = readValue(src, object: TypeReference() {})
inline fun ObjectMapper.treeToValue(n: TreeNode): T = treeToValue(n, T::class.java)
inline fun ObjectMapper.convertValue(from: Any): T = convertValue(from, object: TypeReference() {})
inline fun ObjectReader.readValue(jp: JsonParser): T = readValue(jp, object: TypeReference() {})
inline fun ObjectReader.readValues(jp: JsonParser): Iterator = readValues(jp, object: TypeReference() {})
inline fun ObjectReader.treeToValue(n: TreeNode): T = treeToValue(n, T::class.java)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy