当前位置:网站首页>【Utils】JsonUtil
【Utils】JsonUtil
2022-07-28 14:10:00 【One duck, one duck】
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
/** * Customized response structure of Tesco mall */
public class JsonUtils {
// Definition jackson object
private static final ObjectMapper MAPPER = new ObjectMapper();
/** * Converts an object to json character string . * <p>Title: pojoToJson</p> * <p>Description: </p> * @param data * @return */
public static String objectToJson(Object data) {
try {
String string = MAPPER.writeValueAsString(data);
return string;
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
/** * take json Result set converted to object * * @param jsonData json data * @param beanType Object object type * @return */
public static <T> T jsonToPojo(String jsonData, Class<T> beanType) {
try {
T t = MAPPER.readValue(jsonData, beanType);
return t;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/** * take json Data to pojo object list * <p>Title: jsonToList</p> * <p>Description: </p> * @param jsonData * @param beanType * @return */
public static <T>List<T> jsonToList(String jsonData, Class<T> beanType) {
JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);
try {
List<T> list = MAPPER.readValue(jsonData, javaType);
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/** * hold json Convert to Map Tool method * @param jsonData * @param keyType * @param valueType * @param <K> * @param <V> * @return */
public static <K,V> Map<K,V> jsonToMap(String jsonData, Class<K> keyType,Class<V> valueType){
JavaType javaType = MAPPER.getTypeFactory().constructMapType(Map.class,keyType,valueType);
try {
Map<K,V> map = MAPPER.readValue(jsonData,javaType);
return map;
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
}
边栏推荐
- IntersectionObserver交叉观察器
- 如何有效进行回顾会议(上)?
- 线程阻塞的三种情况。
- Several efficient APIs commonly used in inventory operation URL
- Security assurance is based on software life cycle -istio authentication mechanism
- 论文研读--Masked Generative Distillation
- TS literacy method - Basic chapter
- 深度学习基础----GNN谱域和空域 (不断完善更新积累)
- 【Utils】JsonUtil
- 走进音视频的世界——FLV视频封装格式
猜你喜欢
![[basic course of flight control development 7] crazy shell · open source formation UAV SPI (barometer data acquisition)](/img/ad/e0bc488c238a260768f7e7faec87d0.png)
[basic course of flight control development 7] crazy shell · open source formation UAV SPI (barometer data acquisition)

Redis sentinel mechanism

每日一题——奖学金

【LVGL事件(Events)】事件在不同组件上的应用(一)

离散对数问题(DLP) && Diffie-Hellman问题(DHP)

Security assurance is based on software life cycle -psp application

Multi level cache scheme

Chapter 6 support vector machine

文献阅读(245)Roller

Jmeter安装教程及登录增加token
随机推荐
R language test sample proportion: use prop The test function performs the single sample proportion test to calculate the confidence interval of the p value of the successful sample proportion in the
MySql5.5之后的默认存储引擎为InnoDB。
在centos中安装mysql5.7.36
Jmeter安装教程及登录增加token
多级缓存方案
Master several common sorting - Select Sorting
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置draw_quantiles参数添加指定分位数横线(例如,50%分位数、中位数)
VOS3000如何呼入送到OKCC
Read how to deploy highly available k3s with external database
Websocket chat
【翻译】盐业公司来Linkerd公司是为了负载平衡,留下来是为了效率、可靠性和性能。...
Security assurance is based on software life cycle -istio authentication mechanism
Multithreading and high concurrency (III) -- source code analysis AQS principle
盘点操作URL中常用的几个高效API
文献阅读(245)Roller
Rust from introduction to mastery 01 introduction
目标检测:速度和准确性比较(Fater R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)
The strongest distributed locking tool: redisson
了解虚拟列表背后原理,轻松实现虚拟列表
R language uses dpois function to generate Poisson distribution density data and plot function to visualize Poisson distribution density data