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 |

相关推荐
文丑颜不良啊1 小时前
LeetCode3421~3440题目解析
java·leetcode
code2cat2 小时前
【随笔】Java客户端选了HTTP/3,怎样知道请求实际走了哪个版本
java·开发语言·http
码云社区3 小时前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案
java·vue.js·vr·租房小程序·在线租房·看房租房
码云社区4 小时前
Spring Boot智慧物业系统源码:合同到期提醒、续签资料与资产协作
java·spring boot·后端·物业管理·物业系统·智慧物业
AI开源软件4 小时前
Vue3+SpringBoot3 业务配置统一管理:接管、保存与回退怎样保留有效值
java·前端·vue.js·spring boot·vue·ruoyi office
陈如水4 小时前
Spring AI Alibaba 在多 Agent 场景下的实践
java·人工智能·spring
杨运交4 小时前
091-功能模块-API Key 管理功能模块解析:feature-sa-token 架构设计与数据库持久化
spring boot
行百里er5 小时前
【Spring Insight 技术分享】如何给 AI 接口调用做滑动窗口限流
spring boot·后端·spring cloud
有个傻瓜5 小时前
一次「查到别家门店订单」的线上事故:Spring Boot 3 + MyBatis-Plus 多租户隔离踩坑复盘
spring boot·mybatis-plus·多租户·ruoyi-vue-plus·线上故障复盘
吃我一窝jio5 小时前
Docker+Jenkins+K8s全流程部署
java·开发语言·笔记·python