Spring Boot 使用json框架fastjson
来源:互联网 发布:js刷新页面 编辑:程序博客网 时间:2024/06/03 17:21
使用Json框架Fastjson替换Spring Boot默认Jackson
1. 第一种方法
/** * 配置类:利用fastjson替换springboot默认的jackson * Created by gaozhy on 2017/6/4 0004. */@Configurationpublic class WebMvcConfig extends WebMvcConfigurerAdapter { public void configureMessageConverters(List<HttpMessageConverter<?>> converters){ // 1. 创建json转换器 FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); // 2. 格式化相应json格式 fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); // 3. 处理中文乱码 ArrayList<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.APPLICATION_JSON_UTF8); converter.setSupportedMediaTypes(mediaTypes); // 4. 配置converter converter.setFastJsonConfig(fastJsonConfig); // 5. 添加 converters.add(converter); }}
/** * springboot启动类 *@SpringBootApplicationpublic class SpringBoot01Application{ public static void main(String[] args){ SpringApplication.run(SpringBoot01Application.class,args); }}
2. 第二种办法
@SpringBootApplicationpublic class SpringBoot01Application{ /** * 使用fastjson * @return */ @Bean public HttpMessageConverters createMessageConverters(){ // 1. 创建json转换器 FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); // 2. 格式化相应json格式 fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); // 3. 处理中文乱码 ArrayList<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.APPLICATION_JSON_UTF8); converter.setSupportedMediaTypes(mediaTypes); // 4. 配置converter converter.setFastJsonConfig(fastJsonConfig); // 5. 创建转换器 HttpMessageConverter httpMessageConverter = converter; return new HttpMessageConverters(httpMessageConverter); } public static void main(String[] args){ SpringApplication.run(SpringBoot01Application.class,args); }}
阅读全文
0 0
- Spring Boot 使用json框架fastjson
- Spring-boot中使用fastjson作为json框架
- Spring Boot使用FastJson解析JSON数据
- spring boot:使用fastJson解析json数据
- spring boot 使用fastjson
- spring boot使用fastjson
- 4. Spring Boot 完美使用FastJson解析Json数据
- Spring Boot 学习4--完美使用FastJson解析Json数据
- 【Spring Boot】完美使用FastJson解析JSON数据
- Spring Boot 使用第三方json解析 : fastjson
- Spring Boot完美使用FastJson解析JSON数据(十三)
- (4)Spring Boot完美使用FastJson解析JSON数据【从零开始学Spring Boot】
- 78. Spring Boot完美使用FastJson解析JSON数据【从零开始学Spring Boot】
- 78. Spring Boot完美使用FastJson解析JSON数据【从零开始学Spring Boot】
- spring-boot实现FastJson解析json数据
- spring boot 配置fastjson解析json
- spring boot 使用fastjson 处理json数据中文乱码 默认使用 ISO-8859-1编码格式
- spring boot新手教程之使用FastJson解析JSON数据以及解决返回中文乱码问题
- RMQ算法
- 系统设计二之实例门户网站
- 自然抠图算法:以经典的贝叶斯抠图为例(Bayesian Matting)
- leetcode283题解
- qwb去面试 思路+代码
- Spring Boot 使用json框架fastjson
- 84 C语言带参宏定义和函数的区别
- c语言中,关于延迟函数的理解
- 拓扑排序
- Android 中ArrayAdapter,SimpleAdapter,BaseAdapter三种适配器的使用
- 静态库与动态库
- JAVA学习笔记——Array工具类以及基本类型包装类
- 输出素数
- 只会写代码没有什么厉害的,关键是理解他的原理