锁定老帖子 主题:fastjson发布1.1.5版本
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-09-26
wtusmchen 写道 我在项目中用到了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); 1、性能问题,也许你的测试方法不是很恰当,1.1.2之后性能有很大提升的。 2、你提交的BUG问题重现并且确认,是因为存在List list这个字段导致的,如果你修改为List<Object> list就会好了。 Bug已经修复: JIRA ISSUE : http://code.alibabatech.com/jira/browse/FASTJSON-100 回归测试:http://code.alibabatech.com/svn/fastjson/trunk/fastjson/src/test/java/com/alibaba/json/test/bvt/bug/Bug_for_wtusmchen.java |
|
返回顶楼 | |
发表时间:2011-09-26
可是我代码没变,只是把1.1.1改成1.1.6,性能就差了很多。就是很简单的重复序列化一个list
|
|
返回顶楼 | |
发表时间:2011-10-26
JSON to Bean 有问题,请教下
[com.alibaba.fastjson.JSONException: For input string: "2011-10-16 18:06"] with root cause java.lang.NumberFormatException: For input string: "2011-10-16 18:06" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Long.parseLong(Long.java:419) at java.lang.Long.parseLong(Long.java:468) at com.alibaba.fastjson.parser.deserializer.TimestampDeserializer.deserialze(TimestampDeserializer.java:36) at com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:25) at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:67) at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer$InnerJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:78) at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:207) at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.deserialze(ASMJavaBeanDeserializer.java:31) at Fastjson_ASM_TbRrepairTelephone_1.deserialze(Unknown Source) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:469) at com.alibaba.fastjson.JSON.parseObject(JSON.java:200) at com.tonghuisoft.mos.webapp.action.RepairTelsupportAction.add(RepairTelsupportAction.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270) at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187) at com.tonghuisoft.mos.webapp.action.BaseAction.execute(BaseAction.java:85) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.tonghuisoft.mos.common.SystemFilter.doFilter(SystemFilter.java:45) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at 自定义了一个 Deserializer,然后像下面这样,但是不调用我定义的那个Deserializer,还是调用原有的TimestampDeserializer ParserConfig parserConfig = ParserConfig.getGlobalInstance(); parserConfig.putDeserializer(java.sql.Timestamp.class, RrepairTimeTimestampDeserializer.instance); TbRrepairTelephone tbRrepairTelephone = JSON.parseObject(jsonString, TbRrepairTelephone.class,parserConfig,JSON.DEFAULT_PARSER_FEATURE); |
|
返回顶楼 | |
发表时间:2011-10-26
最后修改:2011-10-26
|
|
返回顶楼 | |
发表时间:2011-10-26
谢谢,文档中发序列反序列化的资料比较少,如果能在 parserConfig 不是根据类型设置,而是可以根据字段名配置比较好,因为比如有两个字段,a,b都是java.util.Date,但是a的格式yyyymmdd 但是b的格式为yyyymmddmm 就不能区分了。
@JSONField不能用于反序列化么? |
|
返回顶楼 | |
发表时间:2011-10-26
如果在parserConfig 在反序列化增加parserConfig.setIncludeParseFileds("fieldName1","fieldName2","fieldName3");就只解析这几个filed,或者parserConfig.setExcludeParseFileds("fieldName1","fieldName2","fieldName3");同样在序列号增加类似的方法,而不是使用filter,就方便了。
parserConfig.addIncludeParseFiled("filedName1").addParsePatten("yyyy-mm-dd mm:ss");等。 |
|
返回顶楼 | |
发表时间:2011-10-27
当序列化 JavassistLazyInitializer 代理过的对象的时候,出错
严重: Servlet.service() for servlet [action] in context with path [/mos] threw exception [java.lang.IncompatibleClassChangeError: Found interface java.sql.Connection, but class was expected] with root cause java.lang.IncompatibleClassChangeError: Found interface java.sql.Connection, but class was expected at Serializer_52.write1(Unknown Source) at Serializer_52.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:321) at Serializer_51.write1(Unknown Source) at Serializer_51.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:321) at Serializer_6.write1(Unknown Source) at Serializer_6.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:321) at Serializer_4.write1(Unknown Source) at Serializer_4.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:321) at Serializer_3.write1(Unknown Source) at Serializer_3.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:321) at Serializer_2.write1(Unknown Source) at Serializer_2.write(Unknown Source) at com.alibaba.fastjson.serializer.MapSerializer.write(MapSerializer.java:145) at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:300) at com.alibaba.fastjson.JSON.toJSONString(JSON.java:426) at com.tonghuisoft.mos.webapp.maptaskaction.AtmLineAction.editSubmit(AtmLineAction.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270) at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187) at com.tonghuisoft.mos.webapp.action.BaseAction.execute(BaseAction.java:90) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.tonghuisoft.mos.common.SystemFilter.doFilter(SystemFilter.java:45) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:279) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) google gson 序列号的结果 {"handler":{"interfaces":[{}],"constructed":true,"persistentClass":{},"getIdentifierMethod":{"clazz":{},"slot":1,"name":"getId","returnType":{},"parameterTypes":[],"exceptionTypes":[],"modifiers":1,"root":{"clazz":{},"slot":1,"name":"getId","returnType":{},"parameterTypes":[],"exceptionTypes":[],"modifiers":1,"override":false},"override":false},"setIdentifierMethod":{"clazz":{},"slot":4,"name":"setId","returnType":{},"parameterTypes":[{}],"exceptionTypes":[],"modifiers":1,"root":{"clazz":{},"slot":4,"name":"setId","returnType":{},"parameterTypes":[{}],"exceptionTypes":[],"modifiers":1,"override":false},"override":false},"overridesEquals":false,"entityName":"com.tonghuisoft.mos.webapp.maptaskaction.AtmLineModel","id":"4028128133446d4a0133446f70eb0001","target":{"id":"4028128133446d4a0133446f70eb0001","lineName":"线路名称","lineCode":"线路编码","lineDescription":"线路描述","createTime":"Oct 27, 2011 4:11:53 PM","version":0},"initialized":true,"readOnly":false,"unwrap":false}} |
|
返回顶楼 | |
发表时间:2012-09-17
用fastjson
转对象时返回为空,不知道是什么原因呢 以下是服务器返回的字串.jsonString ={"rnname":"包","pknumspec":"160g*1","pknum":"24","rnum":"24","rnumspec":"24","pkname":"160g*1"}转为对象时goodsdetailactivity [rNName=null, rNum=null, rNumSpec=null]有没高人看下. |
|
返回顶楼 | |