jackson的工具类

册噩噩 册噩噩 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

package com.example.fuxi.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.text.SimpleDateFormat;
public class jsonUntil {

public static String getJson(Object obj) {
return getJson(obj,"YYYY-MM-DD HH:MM:SS");
}

public static String getJson(Object obj,String DateFormat) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false);
final SimpleDateFormat sdf = new SimpleDateFormat(DateFormat);
mapper.setDateFormat(sdf);
try {
return mapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}

}


是不是很简洁
...全文
评论 1
收藏 已收藏
分享
返回顶部
册噩噩
Web 开发 81,108 成员 341,721 内容