推荐 jackson

依赖

        <!-- fastjson https://mvnrepository.com/artifact/com.alibaba/fastjson --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.75</version></dependency><!-- 工具集 https://mvnrepository.com/artifact/cn.hutool/hutool-all --><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.5.8</version></dependency><!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.12.1</version>
</dependency>
JsonUtil (jackson)
package com.gw.common.utils;import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;import java.util.List;/*** @Title: jackson工具类* @Description: 描述* @Version: v1.0* @Author: Mr.Guan* @Mail GuanWeiMail@163.com* @DateTime: 2021-02-24* @Project springcloud-gw-parent* @Package com.guanwei.study.json*/
public class JsonUtil {/*** 定义jackson对象*/private static final ObjectMapper MAPPER = new ObjectMapper();/*** 将对象转换成json字符串。* <p>Title: pojoToJson</p>* <p>Description: </p>* @param data* @return*/public static String toJsonStr(Object data) {try {
//            ObjectWriter writer = MAPPER.writer();
//            String string = writer.writeValueAsString(data);String string = MAPPER.writeValueAsString(data);return string;} catch (JsonProcessingException e) {e.printStackTrace();}return null;}/*** 将json结果集转化为对象** @param jsonData json数据* @param beanType 对象中的object类型* @return*/public static <T> T toPojo(String jsonData, Class<T> beanType) {try {T t = MAPPER.readValue(jsonData, beanType);return t;} catch (Exception e) {e.printStackTrace();}return null;}/*** 将json数据转换成pojo对象list* <p>Title: jsonToList</p>* <p>Description: </p>* @param jsonData* @param beanType* @return*/public static <T> List<T> jsonToList(String jsonData, Class<T> beanType) {JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);try {List<T> list = MAPPER.readValue(jsonData, javaType);return list;} catch (Exception e) {e.printStackTrace();}return null;}/*** 获取ObjectMapper* @return*/public static ObjectMapper getObjectMapper() {return JsonUtil.MAPPER;}}
package com.guanwei.study.json;import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gw.common.utils.JsonUtil;import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;/*** @Title: 测试JSON性能* @Description: jacksonUtil 胜出* @Version: v1.0* @Author: Mr.Guan* @Mail GuanWeiMail@163.com* @DateTime: 2021-02-24* @Project springcloud-gw-parent* @Package com.guanwei.study.json*/
public class JsonTest {/*** 多线程数量*/private static final int mulThreadCount = 1000;private static final int count = 100000;/*** Spring 中默认用到的是Jackson* jacksonUtil 胜出* @param str*/public static void main(String [] str) {Map map = new HashMap<String,Object>(1000000);map = getMapData(map,1000000);int count = JsonTest.count;//hutoolJsonlong hutoolJsonBegin =  System.currentTimeMillis();JSONUtil.toJsonStr(map);for (int i = 0; i < count; i++) {JSONUtil.toJsonStr(new HashMap<>());}long hutoolJsonEnd =  System.currentTimeMillis();System.out.println("hutoolJson-------------time------------------------------------"+(hutoolJsonEnd-hutoolJsonBegin));//jacksonlong jacksonBegin =  System.currentTimeMillis();ObjectMapper jackson = new ObjectMapper();try {jackson.writeValueAsString(map);for (int i = 0; i < count; i++) {jackson.writeValueAsString(new HashMap<>());}long jacksonEnd =  System.currentTimeMillis();System.out.println("jackson-------------time------------------------------------"+(jacksonEnd-jacksonBegin));} catch (JsonProcessingException e) {e.printStackTrace();}//jackson工具 (推荐 速度最快)long jacksonBegin1 =  System.currentTimeMillis();JsonUtil.toJsonStr(map);for (int i = 0; i < count; i++) {JsonUtil.toJsonStr(new HashMap<>());}long jacksonEnd1 =  System.currentTimeMillis();System.out.println("jacksonUtil-------------time------------------------------------"+(jacksonEnd1-jacksonBegin1));//fastJsonlong fastJsonBegin =  System.currentTimeMillis();String s = JSONObject.toJSONString(map);for (int i = 0; i < count; i++) {JSONObject.toJSONString(new HashMap<>());}long fastJsonEnd =  System.currentTimeMillis();System.out.println("fastJson-------------time------------------------------------"+(fastJsonEnd-fastJsonBegin));JsonTest.testMulThreadFastJson();JsonTest.testMulThreadJacksonUtil();}/*** 多线程模式jacksonUtil** @throws InterruptedException*/public static void testMulThreadJacksonUtil() {CountDownLatch countDownLatch = new CountDownLatch(mulThreadCount);long start = System.currentTimeMillis();for (int i = 0; i < mulThreadCount; i++) {int finalI = i;new Thread(() -> {JsonUtil.toJsonStr(new HashMap<>(1));countDownLatch.countDown();}).start();}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}System.out.println("jacksonUtil 多线程模式最终用时:" + (System.currentTimeMillis() - start) + "ms");}/*** 多线程模式FastJson** @throws InterruptedException*/public static void testMulThreadFastJson() {CountDownLatch countDownLatch = new CountDownLatch(mulThreadCount);long start = System.currentTimeMillis();for (int i = 0; i < mulThreadCount; i++) {int finalI = i;new Thread(() -> {JSONObject.toJSONString(new HashMap<>(1));countDownLatch.countDown();}).start();}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}System.out.println("FastJson 多线程模式最终用时:" + (System.currentTimeMillis() - start) + "ms");}/*** 生成指定数量的map* @param map* @param count* @return*/public static Map getMapData(Map map,int count) {for (int i = 0;i < count;i++) {map.put("a"+i,i);}return map;}}

【性能测试】JSON工具 对比 fastjson jackson相关推荐

  1. Scala中解析json工具对比

    写再前面的总结: 1, 做少量文件解析,优先用json4s,因为json4s时基于Scala开发的,对scala使用场景支持更好 2. 做大量数据的解析,追求序列化.反序列化速度时,考虑用fastjs ...

  2. 阿里巴巴Json工具:Fastjson教程

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 首先我们要了解JSON是什么? JSON(JavaScr ...

  3. SpringMVC之JSON工具:Jackson Gson 和fastjson通过JSON工具来解决文字乱码和时间格式问题——通过JSON工具生成JSON

    什么是Json? JSON:JavaScript Object Notation+JS对象 它是一种轻量级的数据交换格式JSON(当前是交互的顶流),它自身具有独立的编程格式,它的特点是简洁和清晰,J ...

  4. Spring默认使用的JSON工具--Jackson

    一.Jackson介绍 我们常用的json转换工具包括fastJson.Gson.Jackson等.其中Gson是Google所维护,功能全.fastJson特点是快,但是爆出几次的重大bug让人很难 ...

  5. JSON内容对比工具

    一款基于Java的JSON内容对比工具类,结合Jackson一起使用 Maven依赖: <dependency><groupId>com.flipkart.zjsonpatch ...

  6. 用jackson封装的JSON工具类

    package hjp.smart4j.framework.util;import com.fasterxml.jackson.databind.ObjectMapper; import org.sl ...

  7. 在线JSON在线对比差异工具

    在线JSON在线对比差异工具 在线JSON在线对比差异工具 JSON在线对比差异工具,JSON在线对比差异工具,JSON在线对比差异工具 https://tooltt.com/json-diff/

  8. Winform,RichTextBox,Json文本对比工具

    在工作中,有的时候需要做一些Json对比的需求,通过肉眼去找到不一样的地方 当然,现在有很多可以做对比的小工具,比如Beyond Compare 但是这个有个弊端,如果对比的时候是个Json字符串,没 ...

  9. windows + web性能测试工具对比

    web压力性能测试工具对比 apache bench 优点:使用单线程程序,只占用一个CPU,可以用作快速测试工具. 缺点:不能用作严格的测试,往往跑ab的测试机负荷满了,而服务器应用的性能还绰绰有余 ...

  10. java json开发包 fastjson 简介

    Json是一种轻量级的数据交换格式,采用一种"键:值"对的文本格式来存储和表示数据,在系统交换数据过程中常常被使用,是一种理想的数据交换语言.在使用Java做Web开发时,不可避免 ...

最新文章

  1. Cocos2D-Android-1之源码详解:2.ActionManagerTest
  2. 中小型研发团队架构实践:电商如何做企业总体架构?
  3. jedis使用_Mybatis的二级缓存、使用Redis做二级缓存
  4. asterisk channel driver dev ref
  5. 【转】ITK和VTK比较
  6. 谷歌大脑计划研究员Chris Olah的博客
  7. Python爬虫实战(二):爬取快代理构建代理IP池
  8. 西南科技大学oj题逆置顺序表
  9. ibm 服务器 阵列 加硬盘,IBM服务器增加硬盘
  10. Nginx完全正向保密(perfect forward secrecy)设置
  11. linux网络测试工具
  12. warning CS0108: `___' hides inherited member `___'. Use the new keyword if hiding was intended解决办法
  13. 2019年浙江大学计算机考研复试线,2019年浙江大学考研复试分数线已经公布
  14. Ricochet —— 基于 Tor 的加密即时通信工具
  15. 华为国际专利申请数量全球第一,然而美国周刊评了IT行业影响最大的十人
  16. 文献阅读笔记 # Bitcoin: A Peer-to-Peer Electronic Cash System
  17. Mn0.15V2O5·nH2O锌离子电池正极材料的储锌性能
  18. 基础代谢率、BMI、体脂肪率、肌肉量、体水分率,这些都是什么?
  19. 【S2VD】S2VD半监督视频降雨方法(Semi-Supervised Video Deraining with Dynamical Rain Generator)论文学习
  20. python写矩阵奇异值分解

热门文章

  1. 2018-11-3-如何使用-Telegram
  2. Leetcode题解(更新中……)
  3. 浙大PAT甲级题目1061-1080代码详细解答|标准答案|C++语言|浙软机试
  4. python将多个txt内容合并_python合并多个txt文件成为一个文件
  5. 【舆情监控】社会化大数据应用平台TOOM舆情监测系统
  6. Java案例:实现九九乘法表
  7. 【分布式】什么是分布式技术?
  8. 如果在Flutter Web项目中使用lottie动画
  9. OpenCore 启动菜单界面美化增加gui界面
  10. Android studio 导入项目运行