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

com.fireflysource.wechat.utils.JsonUtils.kt Maven / Gradle / Ivy

package com.fireflysource.wechat.utils

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper

/**
 * @author Pengtao Qiu
 */
object JsonUtils {

    val mapper = ObjectMapper()

    fun  read(json: String, clazz: Class): T = mapper.readValue(json, clazz)

    fun  read(json: String, ref: TypeReference): T = mapper.readValue(json, ref)

    inline fun  read(json: String): T = mapper.readValue(json, object : TypeReference() {})

    fun write(obj: Any): String = mapper.writeValueAsString(obj)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy