All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.module.kotlin.Extensions.kt Maven / Gradle / Ivy

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.JsonMappingException
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)


internal fun JsonMappingException.wrapWithPath(refFrom: Any?, refFieldName: String) = JsonMappingException.wrapWithPath(this, refFrom, refFieldName)
internal fun JsonMappingException.wrapWithPath(refFrom: Any?, index: Int) = JsonMappingException.wrapWithPath(this, refFrom, index)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy