SpringBoot消息转换器扩展fastjson

在pom.xml中引入fastjson

<dependency >

<groupId >com.alibaba</groupId >

<artifactId >fastjson</artifactId >

<version >1.2.47</version >
</dependency >

配置消息转换器,添加fastjson

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FastJsonHttpMessageConverter fc = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat );
fc.setFastJsonConfig(fastJsonConfig);
converters.add(fc);
}

创建User实体类

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| public class User { private String username ; private String password ; private int age ; private int score ; private int gender ; @JSONField(format = "yyyy-MM-dd" ) private Date date ; 创建jsoncontroller @Controller public class JsonController { @RequestMapping("/json") @ResponseBody public User json() { User user = new User(); user.setUsername("zhangsan"); user.setPassword("123456"); user.setAge(20); user.setScore(90); user.setGender(1); user.setDate(new Date()); return user; } } 启动项目访问http://localhost:端口号/json |

相关推荐
QQ_216962909636 分钟前
【项目编号:project95315】SpringBoot公共自习室管理系统:座位预约、房间管理、签到核销、公告规则完整实战
java·spring boot·后端
凤山老林41 分钟前
高可用服务容错架构:Spring Boot 集成 Resilience4j 实战指南
spring boot·后端·架构·resilience4j
手握风云-1 小时前
Spring Cloud:分布式系统的“粘合剂”(五)
后端·spring·spring cloud
嵌入式阿蔡1 小时前
面试高频考点 01:volatile / 中断 / 堆栈 八股精讲
java·面试·职场和发展·嵌入式实时数据库
秋饼1 小时前
LangChain4j + Java 实现企业级 Text-to-SQL 智能问数系统:从自然语言到安全可控的数据洞察
java·ai·技术分享·后端开发
Escalating_xu1 小时前
【C++ STL简介】从六大组件到容器、迭代器与算法协作
java·c++·算法
何以解忧,唯有..2 小时前
Python os模块详解:文件与目录操作指南
java·服务器·python
Csxyzj2 小时前
kubernetes集群部署方法
java·linux·kubernetes
SQL-First布道者2 小时前
全面解构传统持久层框架,拥抱真正的 SQL-First
java·数据库·spring boot·sql·spring·mybatis·spring jdbc
小蒜学长2 小时前
vue旅游攻略网站(代码+数据库+LW)
java·数据库·vue.js·spring boot·后端·旅游