123456789101112131415161718 |
- 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> T fromJson(String jsonStr,Class<T> clazz) throws Exception {
- return objectMapper.readValue(jsonStr,clazz);
- }
- }
|