springboot实现FastJson解析json数据的方法
发布时间 - 2026-01-11 00:53:50 点击率:次最近在研究springboot实现FastJson解析json数据的方法,那么今天也算个学习笔记吧!

添加jar包:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
两种方式启动加载类:
第一种继承WebMvcConfigurerAdapter,重写configureMessageConverters方法:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
@SpringBootApplication
public class App extends WebMvcConfigurerAdapter{
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
// TODO Auto-generated method stub
super.configureMessageConverters(converters);
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(
SerializerFeature.PrettyFormat
);
fastConverter.setFastJsonConfig(fastJsonConfig);
converters.add(fastConverter);
}
}
第二种方式bean注入HttpMessageConverters:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
@SpringBootApplication
public class AppTwo{
public static void main(String[] args) {
SpringApplication.run(AppTwo.class, args);
}
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}
}
最后属性前加@JSONField:
@JSONField(serialize=false) private Long id;
返回前端就会没有id这个属性值
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# spring
# boot
# fastjson
# 解析json
# springboot
# fastjsong
# springboot中使用FastJson解决long类型在js中失去精度的问题
# SpringBoot整合Gson 整合Fastjson的实例详解
# SpringBoot如何使用Fastjson解析Json数据
# springboot中用fastjson处理返回值为null的属性值
# 使用SpringBoot+OkHttp+fastjson实现Github的OAuth第三方登录
# SpringBoot整合FastJson过程解析
# SpringBoot Redis配置Fastjson进行序列化和反序列化实现
# Spring Boot使用FastJson解析JSON数据的方法
# Spring boot详解fastjson过滤字段为null值如何解决
# 就会
# 两种
# 重写
# 也算
# 第二种
# 第一种
# 大家多多
# 学习笔记
# 加载
# import
# java
# org
# configureMessageConverters
# serializer
# autoconfigure
# annotation
# WebMvcConfigurerAdapter
# springframework
# HttpMessageConverter
# converter
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
Android使用GridView实现日历的简单功能
Laravel如何实现多对多模型关联?(Eloquent教程)
Swift开发中switch语句值绑定模式
怎么制作一个起泡网,水泡粪全漏粪育肥舍冬季氨气超过25ppm,可以有哪些措施降低舍内氨气水平?
Edge浏览器提示“由你的组织管理”怎么解决_去除浏览器托管提示【修复】
JS中页面与页面之间超链接跳转中文乱码问题的解决办法
javascript如何操作浏览器历史记录_怎样实现无刷新导航
Laravel怎么使用Intervention Image库处理图片上传和缩放
如何在局域网内绑定自建网站域名?
Laravel怎么进行数据库事务处理_Laravel DB Facade事务操作确保数据一致性
Laravel安装步骤详细教程_Laravel环境搭建指南
edge浏览器无法安装扩展 edge浏览器插件安装失败【解决方法】
湖南网站制作公司,湖南上善若水科技有限公司做什么的?
Java Adapter 适配器模式(类适配器,对象适配器)优缺点对比
Laravel如何获取当前登录用户信息_Laravel Auth门面使用与Session用户读取【技巧】
Laravel如何设置定时任务(Cron Job)_Laravel调度器与任务计划配置
今日头条AI怎样推荐抢票工具_今日头条AI抢票工具推荐算法与筛选【技巧】
高防服务器租用首荐平台,企业级优惠套餐快速部署
佛山网站制作系统,佛山企业变更地址网上办理步骤?
音乐网站服务器如何优化API响应速度?
Laravel如何配置.env文件管理环境变量_Laravel环境变量使用与安全管理
制作ppt免费网站有哪些,有哪些比较好的ppt模板下载网站?
Laravel怎么清理缓存_Laravel optimize clear命令详解
Laravel API路由如何设计_Laravel构建RESTful API的路由最佳实践
google浏览器怎么清理缓存_谷歌浏览器清除缓存加速详细步骤
jquery插件bootstrapValidator表单验证详解
绝密ChatGPT指令:手把手教你生成HR无法拒绝的求职信
laravel怎么用DB facade执行原生SQL查询_laravel DB facade原生SQL执行方法
零服务器AI建站解决方案:快速部署与云端平台低成本实践
简历在线制作网站免费版,如何创建个人简历?
Laravel Eloquent访问器与修改器是什么_Laravel Accessors & Mutators数据处理技巧
如何续费美橙建站之星域名及服务?
Google浏览器为什么这么卡 Google浏览器提速优化设置步骤【方法】
JavaScript如何实现错误处理_try...catch如何捕获异常?
网站制作公司哪里好做,成都网站制作公司哪家做得比较好,更正规?
如何快速查询网站的真实建站时间?
百度浏览器如何管理插件 百度浏览器插件管理方法
Laravel怎么实现前端Toast弹窗提示_Laravel Session闪存数据Flash传递给前端【方法】
邀请函制作网站有哪些,有没有做年会邀请函的网站啊?在线制作,模板很多的那种?
网站建设保证美观性,需要考虑的几点问题!
Laravel怎么实现软删除SoftDeletes_Laravel模型回收站功能与数据恢复【步骤】
如何挑选最适合建站的高性能VPS主机?
Laravel如何实现全文搜索功能?(Scout和Algolia示例)
智能起名网站制作软件有哪些,制作logo的软件?
如何在七牛云存储上搭建网站并设置自定义域名?
潮流网站制作头像软件下载,适合母子的网名有哪些?
Laravel如何处理文件下载请求?(Response示例)
Laravel数据库迁移怎么用_Laravel Migration管理数据库结构的正确姿势
如何在Ubuntu系统下快速搭建WordPress个人网站?
laravel服务容器和依赖注入怎么理解_laravel服务容器与依赖注入解析

