按照官方例子,采用如下的写法:
序列化:
JSONWriter writer = new JSONWriter(new FileWriter("/tmp/huge.json")); writer.startArray(); for (int i = 0; i < 1000 * 1000; ++i) { writer.writeObject(new VO()); } writer.endArray(); writer.close();
反序列化:
JSONReader reader = new JSONReader(new FileReader("/tmp/huge.json")); reader.startArray(); while(reader.hasNext()) { VO vo = reader.readObject(VO.class); // handle vo ... } reader.endArray(); reader.close();现在序列化没有问题,但是在反序列化的时候总是报错:
2013-09-15 13:28:31,744 136326 INFO [qtp8745062-57] com.yxhs.controller.TemplateController - com.alibaba.fastjson.JSONException: -1 com.alibaba.fastjson.JSONException: -1 at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:517) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:500) at com.alibaba.fastjson.JSONReader.readObject(JSONReader.java:204) at com.yxhs.controller.TemplateController.importImportedModuleJson(TemplateController.java:1996) at com.yxhs.controller.TemplateController.importMIBDBStart(TemplateController.java:1185) 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.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:547) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:481) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:940) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:409) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:874) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110) at org.eclipse.jetty.server.Server.handle(Server.java:349) at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441) at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:904) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:565) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:46) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:545) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:43) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.ArrayIndexOutOfBoundsException: -1 at com.alibaba.fastjson.parser.JSONReaderScanner.charAt(JSONReaderScanner.java:125) at com.alibaba.fastjson.parser.JSONLexerBase.longValue(JSONLexerBase.java:2805) at com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer.deserialze(AbstractDateDeserializer.java:22) at Fastjson_ASM_ImportedModule_1.deserialze(Unknown Source) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:513) ... 43 mor
什么版本?换了几个版本,1.1.32-1.1.36都出现相同问题
<aclass='referer'target='_blank'>@wenshao,我上传了测试样例,能不能麻烦你帮忙看看?
最近极忙,无暇关注。请到这里github上记录问题,然后我在国庆期间跟进解决。
<arel="nofollow">https://github.com/alibaba/fastjson/issues?state=open
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。