fastjson 在 springboot中的运用
题记: 项目中开始用是Gson,但是压力测试的时候会出现性能下降明显,不得已换成了fastjson
1.首先引用包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.41</version>
</dependency>
2.Application 添加@Bean
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters(){
//1.需要定义一个convert转换消息的对象;
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
//2:添加fastJson的配置信息;
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//3处理中文乱码问题
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
//4.在convert中添加配置信息.
fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastJsonHttpMessageConverter;
return new HttpMessageConverters(converter); }
3.实体注解写法 @JSONField(format="yyyy-MM-dd HH:mm:ss",name = "createTime")
@JSONField(format="yyyy-MM-dd HH:mm:ss",name = "createTime")
private Date createdDate;
@JSONField(name = "picture")
private String imageLink;
@JSONField(name = "playUrl")
private String mobileFileLink;
4.解析json字符串 {"msgId":"ed3ad9d5-005f-4e37-9f7b-fbaf7323d0ae","version":"2.0","timeStamp":1513233213925,"appId":"cms20001","type":"Article","action":"Delete","priority":"Normal","payload":{"entityid":"b3476954-67b0-474c-a7a7-f5f301dda46b","businessid":"6430523"}}
String t = new String(message,"UTF-8");
JSONObject jsonObj = JSON.parseObject(t)
JSONObject payload = jsonObj.getJSONObject("payload");
long collectionId = payload.getLong("businessid");
针对array可以用这个
JSONObject jsonObj = new JSONObject(rawText);
JSONArray jsonArray = result .getJSONArray("selList");
for (int i = 0; i < jsonArray.length; i++) { }
fastjson 在 springboot中的运用的更多相关文章
- SpringBoot中使用Fastjson/Jackson对JSON序列化格式化输出的若干问题
来源 :https://my.oschina.net/Adven/blog/3036567 使用springboot-web编写rest接口,接口需要返回json数据,目前国内比较常用的fastjso ...
- spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架
前言: 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架 spring-boot中使用mybatis持久层框架与原spring项目使用方式 ...
- SpringBoot(七) SpringBoot中的缓存机制
随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决这一问题非常好的手段之一.Spring 3开始提供了强大的基于注解的缓 ...
- SpringBoot中如何灵活的实现接口数据的加解密功能?
数据是企业的第四张名片,企业级开发中少不了数据的加密传输,所以本文介绍下SpringBoot中接口数据加密.解密的方式. 本文目录 一.加密方案介绍二.实现原理三.实战四.测试五.踩到的坑 一.加密方 ...
- springboot中集成memcached
前言 Memcached 是一个高性能的分布式内存对象缓存系统,其存储性能在某些方面不比redis差,甚至在文本类型数据的存储上性能略优于redis,本文将介绍如何在springboot中集成memc ...
- (二)Redis在Mac下的安装与SpringBoot中的配置
1 下载Redis 官网下载,下载 stable 版本,稳定版本. 2 本地安装 解压:tar zxvf redis-6.0.1.tar.gz 移动到: sudo mv redis-6.0.1 /us ...
- SpringBoot中yaml配置对象
转载请在页首注明作者与出处 一:前言 YAML可以代替传统的xx.properties文件,但是它支持声明map,数组,list,字符串,boolean值,数值,NULL,日期,基本满足开发过程中的所 ...
- 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧
做WEB项目,一定都用过JSP这个大牌.Spring MVC里面也可以很方便的将JSP与一个View关联起来,使用还是非常方便的.当你从一个传统的Spring MVC项目转入一个Spring Boot ...
- springboot中swaggerUI的使用
demo地址:demo-swagger-springboot springboot中swaggerUI的使用 1.pom文件中添加swagger依赖 2.从github项目中下载swaggerUI 然 ...
随机推荐
- 提取出一个组装基因组的gap(N)和重复序列区域,保存为bed格式
参见: Question: How to extract allnon-seqencedpositions from a genome (Fasta file)? test.fa >chr1 N ...
- 开发自己的R包(转)
R不必说,数据统计分析可视化的必备语言,R包开发的门槛比较低,所以现在随便一篇文章都会发表一个自己的R包,这样有好处(各种需求早有人帮你解决了)也有坏处(R包太多,混乱,新手上手较难).作为生信工程师 ...
- jenkins+maven+git+tomcat+salt自动构建
jenkins 安装步骤 环境: centos7,jdk1.8.0,jenkins2.165,maven3.5.2 一. 安装配置java环境 JDK1.8下载地址:http://www.orac ...
- PHP单例模式实例,连接数据库对类的引用
<?php//单例模式连接数据库class pzhang{ static private $instance; private static $config; private $dbase = ...
- SWUST OJ(954)
单链表的链接 #include <stdio.h> #include <stdlib.h> typedef struct LinkNode //单链表节点结构的定义 { cha ...
- (三)使用链式数据实现包(java)
目标: 1) 描述数据的链式组织方式 2) 描述如何在链式节点链的开头添加新节点 3) 描述如何删除链式节点链的首节点 4) 描述如何在链式节点链中找到某个数据 5) 使用链式节点链实现ADT包 6) ...
- json加密
有的时候我们为了传参数的URL比较安全,我们一般会用json加密的方法来使自己的URL安全. $a['order_sn'] = $orderNo;$data = json_encode( $a);$d ...
- 函数使用六:ABAP4_CALL_TRANSACTION
此函数是在程序中调用一个事物代码,跳转或者执行事物代码的程序. 参数说明: Import TCODE 执行的事物代码 SKIP_SCREEN ...
- Pick-up sticks
Pick-up sticks Stan has n sticks of various length. He throws them one at a time on the floor in a r ...
- 未能加载文件或程序集“Oracle.DataAccess”或它的某一个 依赖项。如何解决?
之前项目做大数据批量添加使用了OracleBulkCopy,这个是引用Oracle.DataAccess.Client的命名空间,所以项目要引用一个Oracle.DataAccess.dll, 但是运 ...