当前位置:网站首页>JSON tool class
JSON tool class
2022-07-21 20:09:00 【Niuniu's java learning journey】
JSON Tool class
package com.liu.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 JsonUtils {
// Pass a parameter
public static String getJson(Object object){
return getJson(object,"yyyy-MM-dd HH:mm:ss");
}
// Pass two parameters
public static String getJson(Object object,String dateFormat){
ObjectMapper mapper = new ObjectMapper();
// How to turn off timestamp
mapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS,false);
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
mapper.setDateFormat(sdf);
try {
return mapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
}
test
@RestController// Don't go to view parser
public class UserController {
@RequestMapping("/j1")
public String json1(){
// Create an object
User user = new User(" Liu Xiang ",3," male ");
return JsonUtils.getJson(user);
}
result
Good configuration tomcat, Input url test
url:(http://localhost:8080/springmvc_05_json_war_exploded/j1)
result :
边栏推荐
- Read yaml configuration file based on Hydra Library (support command line parameters)
- Gradually understand the deep belief network
- Docker installation mysql8 in CentOS 8
- Wechat public number Development Access, Application for Test number for Local Development Using Wechat public Platform
- (3) Jdbctemplate
- RSA公私钥加密工具类
- Real time tracking of user management operations
- Pycharm创建SQLite数据库
- Unity ECS test demo
- 基于hydra库实现yaml配置文件的读取(支持命令行参数)
猜你喜欢
Introduction, installation and basic use of MYCAT
3D数学之三角公式
整合ssm框架的项目
微信公眾號開發接入,利用微信公眾平臺申請測試號進行本地開發
From March to June, after summary, more than 200 pages of true question notes and detailed explanations (including core test sites and 6 major factories)
How to successfully get offers from ant, jd.com, Xiaomi, Tencent and other major manufacturers
Quartz创建定时任务(入门)
Pycharm创建SQLite数据库
逐步理解深度信念网络
uniapp开发app解决uni.pageScrollTo不生效
随机推荐
对项目优化之一:redis缓存数据库的安装与项目中使用,加强项目读取操作
How do I optimize from 20s to 500ms
Solutions: connections could not be acquired from the underlying database!
MyCat的介绍与安装以及基本使用
Getting started with the gradle project construction tool
3D数学之三角公式
C -- compilation preprocessing
Wechat official account development access, using wechat public platform to apply for test number for local development
判断“String[]”数组中是否有存在重复的值,利用hashSet特性排查
Interview with data center and Bi business (II): pit of organizational structure Sorting
Pychart creates SQLite database
Flutter obtains longitude and latitude through geolocator positioning plug-in and calls Gaode peripheral information interface
Json工具 将对象转换为json格式字符串
Corn expression usage
Corn表达式用法
STM32 - positioning module atgm336h, data analysis, longitude and latitude extraction
In fastjason data type, there is a problem of $ref: "$.list[0]" when parsing jsonobject
3-6月面经总结,200多页真题笔记和详解(含核心考点及6家大厂)
Momenta "flywheel L4" accepted the challenge of "pixel level" in the night long tail scene, and its performance was comparable to that of an old driver
Project debug|no string argument constructor / factory method to deserialize from string val