json工具类

来源:互联网 发布:知到生态文明答案 编辑:程序博客网 时间:2024/05/02 04:32
import java.io.IOException;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.ObjectMapper;/** * @author zhongmin */public class JsonUtil{private static final ObjectMapper objectMapper = new ObjectMapper();public static String toJson(Object value){try{return objectMapper.writeValueAsString(value);} catch (JsonProcessingException e){throw new RuntimeException(e);}}public static <T> T from(Object value, Class<T> valueType){try{return objectMapper.readValue(value.toString(), valueType);} catch (IOException e){throw new RuntimeException(e);}}}

 

0 0
原创粉丝点击