123456789101112131415161718192021222324252627282930313233 |
- package com.wechi.adweb.bridge.util;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import lombok.extern.slf4j.Slf4j;
- /**
- * @author wfansh
- */
- @Slf4j
- public class JsonUtils {
- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
- public static String toJson(Object object) {
- try {
- return OBJECT_MAPPER.writeValueAsString(object);
- } catch (JsonProcessingException e) {
- log.error(e.getMessage(), e);
- return null;
- }
- }
- public <T> T fromJson(String json, Class<T> clazz) {
- try {
- return OBJECT_MAPPER.readValue(json, clazz);
- } catch (JsonProcessingException e) {
- log.error(e.getMessage(), e);
- return null;
- }
- }
- }
|