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)
}