package com.care.util; import com.fasterxml.jackson.databind.ObjectMapper; /** * @version 1.0.0 创建于 2019/8/6 **/ public final class JsonUtil { private JsonUtil(){} private static ObjectMapper objectMapper = new ObjectMapper(); public static String toJson(Object obj) throws Exception { return objectMapper.writeValueAsString(obj); } public static T fromJson(String jsonStr,Class clazz) throws Exception { return objectMapper.readValue(jsonStr,clazz); } }