jackson对象转为json和json的区别

All,I am implementing a vendor specification using JSON and our object structure uses a general return type (i.e. Response) for each message body.
The structure of this body is defined by the specification can cannot be changed.
We have a general object type that returns this generic return type and then we subclass it for each type of message type we want to support.
So we provide an implementation of the generic method to return the specific type.For example:Base Type:public interface…
Hello all, My use case is :I'm parsing a JsonParser object in a deserialize() method. I'd like to try to detect a pattern in the JSON structure from the JsonParser, and if this pattern is not detected, do something else with the original content. I would like to avoid making useless copies just to detect my simple pattern. The problem is, on the JsonParser there is no "rewind()".I decided to use a TokenBuffer that would represent my advance when detecting the pattern in the original JsonParser.…
on June 11, 2016 at 4:13pm
on August 11, 2015 at 4:28pm
on July 11, 2014 at 12:40pm
on November 17, 2013 at 6:55pm
on April 24, 2013 at 6:12pm
on April 24, 2013 at 3:17pm
on April 9, 2013 at 9:31am
on December 13, 2012 at 9:52am
on November 14, 2012 at 8:10pm
on October 14, 2012 at 3:31pm
Started by Matt Pickering in
on Monday.
Started by kpagcha in .
by Tatu Saloranta Jun 28.
Started by Kevin Gallardo in .
by Tatu Saloranta Jun 28.
Started by Georg Eutermoser in .
by Georg Eutermoser Jun 23.
Started by Shashank in
Started by adioss in
Started by Maarten Boekhold in .
by Tatu Saloranta Jun 11.
Started by Aziz OUATTARA in .
by Tatu Saloranta Jun 11.
Started by Felipe Brancaleone in .
by Tatu Saloranta Jun 11.
Started by Mrjojan Mrjo in .
by Tatu Saloranta Jun 11.
Hello, you need to enable JavaScript to use Jackson JSON User Group.
Please check your browser settings or contact your system administrator.吓一跳的结果:fastjson和jackson的简单对比 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 13时,
中午吃完饭无聊,做了个fastjson和jackson的简单对比。fastjson是阿里做的国有开源Java工具包,jackson是spring&mvc内置的json转换工具,孰强孰弱呢?结果吓我一跳!后面三张图,分别是1000条数据、5000条和1W条!
代码片段(6)
1.&[代码]主测试程序&&&&
public class JsonParseTest {
public static void main(String[] args) throws JsonProcessingException {
Monitoring.begin();
List&Corp& list = Lists.newArrayList();
for (int i = 0; i & 1000; i++) {
list.add(fullObject(Corp.class));
Monitoring.end("生成数据");
Monitoring.begin();
jackson(list);
Monitoring.end("Jackson");
Monitoring.begin();
fastjson(list);
Monitoring.end("fastjson");
public static void fastjson(List&Corp& list) {
for (Corp corp : list) {
String string = JSON.toJSONString(corp);
public static void jackson(List&Corp& list) throws JsonProcessingException {
for (Corp corp : list) {
String string = new ObjectMapper().writeValueAsString(corp);
* 填充一个对象(一般用于测试)
public static &T& T fullObject(Class&T& cl) {
t = cl.newInstance();
Method methods[] = cl.getMethods();
for (Method method : methods) {
// 如果是set方法,进行随机数据的填充
if (method.getName().indexOf("set") == 0) {
Class param = method.getParameterTypes()[0];
if (param.equals(String.class)) {
method.invoke(t, randomCodes(5));
} else if (param.equals(Short.class)) {
method.invoke(t, (short) new Random().nextInt(5));
} else if (param.equals(Float.class)) {
method.invoke(t, new Random().nextFloat());
} else if (param.equals(Double.class)) {
method.invoke(t, new Random().nextDouble());
} else if (param.equals(Integer.class)) {
method.invoke(t, new Random().nextInt(10));
} else if (param.equals(Long.class)) {
method.invoke(t, new Random().nextLong());
} else if (param.equals(Date.class)) {
method.invoke(t, new Date());
} else if (param.equals(Timestamp.class)) {
method.invoke(t, new Timestamp(System.currentTimeMillis()));
} else if (param.equals(java.sql.Date.class)) {
method.invoke(t, new java.sql.Date(System.currentTimeMillis()));
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
2.&[代码]Corp类&&&&
public class Corp {
private Integer corpG
private Integer cityId;
private String EN
private String zipC
private String EM
private Integer isEmailO
private Integer EMailC
private Timestamp regDateOnG
private String webStoreU
private Integer isN
private Integer activeD
private Integer isHitsR
private Timestamp regTimeOnZ
private Integer corpT
private Integer corpMajorcategoryId;
private Integer businessRoleId;
private Integer developS
private String isA
private Integer advMemS
private Integer advStockS
private Integer allianceS
private Timestamp lastUpdateT
private Integer corpMajorcategoryId1;
private String keyword1;
private Long certificateP
private Integer isUpdateC
private String buyP
private Integer isOpenS
private String mainP
private String advBrandI
private Integer contactF
private String fastP
//省略getter、setter方法
3.&[代码]小的监控管理类&&&&
public class Monitoring {
private static ThreadLocal&Long& begin = new ThreadLocal&Long&();
public static void begin() {
begin.set(System.currentTimeMillis());
public static void end(String name) {
double time = (System.currentTimeMillis() - begin.get()) / 1000.0;
System.out.println(name + "所用时间(秒):" + time);
4.&[图片] 1000.png&&&&
5.&[图片] 5000.png&&&&
6.&[图片] 10000.png&&&&
开源中国-程序员在线工具:
相关的代码(24)
12回/28341阅
39回/17195阅
23回/15650阅
12回/10615阅
5回/7754阅
12回/4178阅
0回/3975阅
2回/3397阅
16回/2848阅
12回/2564阅
外国人搞的不靠谱
2楼:Rayn-瑞恩 发表于
这个Fast确实体现出来了。。。我现在就用的fastjson
3楼:rockjava 发表于
中午吃完饭你怎么不睡觉?
4楼:游客 发表于
你是马甲吧。
5楼:李在中 发表于
引用来自“rockjava”的评论中午吃完饭你怎么不睡觉?都冬天了,还睡毛觉啊!
6楼:丛林迷雾 发表于
前几天我也看了,准备下一个项目换fastjson
7楼:小-菜 发表于
哎呀~有木有什么风险呀?
兼容?稳定?
8楼:yackee 发表于
我也用的fastjson,目前没有什么问题。
9楼:nealma 发表于
为什魔我的测试结果不是这样的呢?
10楼:李在中 发表于
引用来自“nealma”的评论为什魔我的测试结果不是这样的呢?电脑配置不一样造成了,看cpu能力喽!
11楼:nealma 发表于
引用来自“李在中”的评论引用来自“nealma”的评论为什魔我的测试结果不是这样的呢?电脑配置不一样造成了,看cpu能力喽!我的结果与你的相反,不同的是我是将public
private int status = 200;
private T} 装换成String,你可一再试一试,T为list
12楼:雨花石 发表于
差距好大呀
13楼:产奶的蜗牛 发表于
@& 你滴乱说!你肯定是马甲!你给jackson每次循环都new一个对象!而fastjson用的是一个对象!你没有考虑new对象的时间吧??你把new 放在循环外面试试!看是jackson快还是fastjson快! 你这样不好滴!误导广大的工程师朋友啊!
14楼:产奶的蜗牛 发表于
引用来自“游客”的评论你是马甲吧。这个肯定是马甲!不用说!测试用例都没写对!
15楼:李在中 发表于
引用来自“产奶的蜗牛”的评论@& 你滴乱说!你肯定是马甲!你给jackson每次循环都new一个对象!而fastjson用的是一个对象!你没有考虑new对象的时间吧??你把new 放在循环外面试试!看是jackson快还是fastjson快! 你这样不好滴!误导广大的工程师朋友啊!谢谢提醒,都没发现,水啦!
16楼:产奶的蜗牛 发表于
引用来自“李在中”的评论引用来自“产奶的蜗牛”的评论@& 你滴乱说!你肯定是马甲!你给jackson每次循环都new一个对象!而fastjson用的是一个对象!你没有考虑new对象的时间吧??你把new 放在循环外面试试!看是jackson快还是fastjson快! 你这样不好滴!误导广大的工程师朋友啊!谢谢提醒,都没发现,水啦!共勉之
17楼:半壶莫提 发表于
引用来自“产奶的蜗牛”的评论引用来自“李在中”的评论引用来自“产奶的蜗牛”的评论@& 你滴乱说!你肯定是马甲!你给jackson每次循环都new一个对象!而fastjson用的是一个对象!你没有考虑new对象的时间吧??你把new 放在循环外面试试!看是jackson快还是fastjson快! 你这样不好滴!误导广大的工程师朋友啊!谢谢提醒,都没发现,水啦!共勉之objectMapper单例线程安全的,用它的案例我测了一下 jackson:1000条:0.203;5000条:0.422,10000条:0.688
18楼:jdonee 发表于
我测了一下 ,低于20000条 Jackson比fastjson稍快,超过20000条以上,fastjson明显会比jackson高很多。
19楼:张志君 发表于
我测了下,最多测试到10万数据,都是jackson要快些,前提是将ObjectMapper定义为静态的
20楼:Confused 发表于
不是吧,同样的代码,上边说的jackson那个new对象造成迟缓,我修改了下同一个对象下,4000条记录以下fastjson快,往上去就是jackson快了
开源从代码分享开始
李在中的其它代码<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&}

我要回帖

更多关于 jackson对象转为json 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信