锁定老帖子 主题:fastjson发布1.1.5版本
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-09-22
能不能给个和Spring集成的例子呢?
比如像Jackson这样的? org.springframework.web.servlet.view.json.MappingJacksonJsonView 通过代理配置能实现使用 fastJSON 序列化 返回集? 谢谢~ |
|
返回顶楼 | |
发表时间:2011-09-22
struts2中如何使用?能否直接替换struts2-json-plugin这样的东西,而在使用过程中依旧通过struts提供的annotation result type="json"方式?
|
|
返回顶楼 | |
发表时间:2011-09-23
最后修改:2011-09-23
{"BX-20110613-1739":{"repairNum":"BX-20110613-1739", "set":[ {"employNum":"a1027","isConfirm":false,"isReceive":false,"state":11}]}, "BX-20110613-1749":{"repairNum":"BX-20110613-1749", "set":[{"employNum":"a1027","isConfirm":false,"isReceive":true,"state":1}]}} 上面是有下面的的代码生成的 Map<String, TaskMobileStatusBean> taskMobileStatusMap public class TaskMobileStatusBean { private String repairNum; private Set<PeopleTaskMobileStatusBean> set=new HashSet<PeopleTaskMobileStatusBean>(); public String getRepairNum() { return repairNum; } public void setRepairNum(String repairNum) { this.repairNum = repairNum; } public Set<PeopleTaskMobileStatusBean> getSet() { return set; } public void setSet(Set<PeopleTaskMobileStatusBean> set) { this.set = set; } } 生成后,从jsonTring 生成map报错信息为 Caused by: com.alibaba.fastjson.JSONException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:286) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:195) at com.alibaba.fastjson.parser.DefaultExtJSONParser.parseObject(DefaultExtJSONParser.java:108) at com.alibaba.fastjson.JSON.parseObject(JSON.java:190) at com.alibaba.fastjson.JSON.parseObject(JSON.java:152) at com.alibaba.fastjson.JSON.parseObject(JSON.java:245) at com.tonghuisoft.mos.common.InitMosBean.initTaskMobileStatus(InitMosBean.java:38) at com.tonghuisoft.mos.common.InitMosBean.init(InitMosBean.java:21) at com.tonghuisoft.mos.common.InitMosBean.afterPropertiesSet(InitMosBean.java:26) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 20 more Caused by: java.lang.NullPointerException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.parseObject(DefaultObjectDeserializer.java:109) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:281) ... 30 more 不能能够返回去么,fastjson-1.1.2 |
|
返回顶楼 | |
发表时间:2011-09-23
rendong 写道 {"BX-20110613-1739":{"repairNum":"BX-20110613-1739", "set":[ {"employNum":"a1027","isConfirm":false,"isReceive":false,"state":11}]}, "BX-20110613-1749":{"repairNum":"BX-20110613-1749", "set":[{"employNum":"a1027","isConfirm":false,"isReceive":true,"state":1}]}} 上面是有下面的的代码生成的 Map<String, TaskMobileStatusBean> taskMobileStatusMap public class TaskMobileStatusBean { private String repairNum; private Set<PeopleTaskMobileStatusBean> set=new HashSet<PeopleTaskMobileStatusBean>(); public String getRepairNum() { return repairNum; } public void setRepairNum(String repairNum) { this.repairNum = repairNum; } public Set<PeopleTaskMobileStatusBean> getSet() { return set; } public void setSet(Set<PeopleTaskMobileStatusBean> set) { this.set = set; } } 生成后,从jsonTring 生成map报错信息为 Caused by: com.alibaba.fastjson.JSONException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:286) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:195) at com.alibaba.fastjson.parser.DefaultExtJSONParser.parseObject(DefaultExtJSONParser.java:108) at com.alibaba.fastjson.JSON.parseObject(JSON.java:190) at com.alibaba.fastjson.JSON.parseObject(JSON.java:152) at com.alibaba.fastjson.JSON.parseObject(JSON.java:245) at com.tonghuisoft.mos.common.InitMosBean.initTaskMobileStatus(InitMosBean.java:38) at com.tonghuisoft.mos.common.InitMosBean.init(InitMosBean.java:21) at com.tonghuisoft.mos.common.InitMosBean.afterPropertiesSet(InitMosBean.java:26) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 20 more Caused by: java.lang.NullPointerException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.parseObject(DefaultObjectDeserializer.java:109) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:281) ... 30 more 不能能够返回去么,fastjson-1.1.2 这个应该是Set类型的字段处理不当导致的,欢迎使用新版本验证问题是否存在。 最新版本: http://code.alibabatech.com/wiki/display/FastJSON/Release+Notes+%281.1.6%29 http://code.alibabatech.com/mvn/releases/com/alibaba/fastjson/1.1.6/ |
|
返回顶楼 | |
发表时间:2011-09-23
最后修改:2011-09-23
var a={1:"2","3":4,'5':6};
alert(a["1"]); //should be String "2" alert(a[3]); //should be number 4 alert(a["3"]); //should be number 4 alert(a['3']); //should be number 4 alert(a[5]); //should be Number 6 这种key是数字的,可能没加引号,可以加了单引号,可能加了比引号,可能是几种的混合的。不知道支持否? |
|
返回顶楼 | |
发表时间:2011-09-23
mfkvfn 写道 var a={1:"2","3":4,'5':6};
alert(a["1"]); //should be String "2" alert(a[3]); //should be number 4 alert(a["3"]); //should be number 4 alert(a['3']); //should be number 4 alert(a[5]); //should be Number 6 这种key是数字的,可能没加引号,可以加了单引号,可能加了比引号,可能是几种的混合的。不知道支持否? 支持的,不过你必须明确并明Map的Key是Object类型。如下: Map<Object, Object> map = JSON.parseObject("{1:\"2\",\"3\":4,'5':6}", new TypeReference<Map<Object, Object>>() {}); Assert.assertEquals("2", map.get(1)); Assert.assertEquals(4, map.get("3")); Assert.assertEquals(6, map.get("5")); |
|
返回顶楼 | |
发表时间:2011-09-23
最后修改:2011-09-23
wenshao 写道 rendong 写道 {"BX-20110613-1739":{"repairNum":"BX-20110613-1739", "set":[ {"employNum":"a1027","isConfirm":false,"isReceive":false,"state":11}]}, "BX-20110613-1749":{"repairNum":"BX-20110613-1749", "set":[{"employNum":"a1027","isConfirm":false,"isReceive":true,"state":1}]}} 上面是有下面的的代码生成的 Map<String, TaskMobileStatusBean> taskMobileStatusMap public class TaskMobileStatusBean { private String repairNum; private Set<PeopleTaskMobileStatusBean> set=new HashSet<PeopleTaskMobileStatusBean>(); public String getRepairNum() { return repairNum; } public void setRepairNum(String repairNum) { this.repairNum = repairNum; } public Set<PeopleTaskMobileStatusBean> getSet() { return set; } public void setSet(Set<PeopleTaskMobileStatusBean> set) { this.set = set; } } 生成后,从jsonTring 生成map报错信息为 Caused by: com.alibaba.fastjson.JSONException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:286) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:195) at com.alibaba.fastjson.parser.DefaultExtJSONParser.parseObject(DefaultExtJSONParser.java:108) at com.alibaba.fastjson.JSON.parseObject(JSON.java:190) at com.alibaba.fastjson.JSON.parseObject(JSON.java:152) at com.alibaba.fastjson.JSON.parseObject(JSON.java:245) at com.tonghuisoft.mos.common.InitMosBean.initTaskMobileStatus(InitMosBean.java:38) at com.tonghuisoft.mos.common.InitMosBean.init(InitMosBean.java:21) at com.tonghuisoft.mos.common.InitMosBean.afterPropertiesSet(InitMosBean.java:26) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 20 more Caused by: java.lang.NullPointerException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.parseObject(DefaultObjectDeserializer.java:109) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:281) ... 30 more 不能能够返回去么,fastjson-1.1.2 这个应该是Set类型的字段处理不当导致的,欢迎使用新版本验证问题是否存在。 最新版本: http://code.alibabatech.com/wiki/display/FastJSON/Release+Notes+%281.1.6%29 http://code.alibabatech.com/mvn/releases/com/alibaba/fastjson/1.1.6/ 用fastjson/1.1.6测试了,还是有上面的问题 Caused by: com.alibaba.fastjson.JSONException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:329) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:231) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:377) at com.alibaba.fastjson.JSON.parseObject(JSON.java:198) at com.alibaba.fastjson.JSON.parseObject(JSON.java:158) at com.alibaba.fastjson.JSON.parseObject(JSON.java:273) at com.tonghuisoft.mos.common.InitMosBean.initTaskMobileStatus(InitMosBean.java:51) at com.tonghuisoft.mos.common.InitMosBean.init(InitMosBean.java:23) at com.tonghuisoft.mos.common.InitMosBean.afterPropertiesSet(InitMosBean.java:27) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 20 more Caused by: java.lang.NullPointerException at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.parseObject(DefaultObjectDeserializer.java:144) at com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer.deserialze(DefaultObjectDeserializer.java:324) |
|
返回顶楼 | |
发表时间:2011-09-23
我测试了,问题没有重现,你看看测试代码有什么不对的:
http://code.alibabatech.com/svn/fastjson/trunk/fastjson/src/test/java/com/alibaba/json/test/bvt/bug/Bug_for_rendong.java |
|
返回顶楼 | |
发表时间:2011-09-23
最后修改:2011-09-23
wenshao 写道 我测试了,问题没有重现,你看看测试代码有什么不对的:
http://code.alibabatech.com/svn/fastjson/trunk/fastjson/src/test/java/com/alibaba/json/test/bvt/bug/Bug_for_rendong.java 辛苦,谢谢,没有问题了。 |
|
返回顶楼 | |
发表时间:2011-09-26
我在项目中用到了fastjson1.1.1,最近测试了1.1.5,1.1.6,遇到两个问题,麻烦温少给看看:
1.速度下降很多,对size为100的list序列化5000次,用JACKSON耗时982,fastjson1.1.1耗时967,fastjson1.1.6耗时3225 2.反序列化出错,jackson和fastjson都没有问题,1.1.5和1.1.6都会出现异常 java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType 代码如下: public class User implements Serializable{ private String user_id = "aaaa"; Date bri; Timestamp bri2; Double num; List list; ... } 序列化 for(int i=0; i<count; i++){ json = JSON.toJSONString(list); } 反序列化 List<User> tt = JSON.parseArray(json, User.class); |
|
返回顶楼 | |