一、异常描述
关于基于alibaba的fastjson.jar包实现字符串及对象集合间转换(具体示例参考示例页面),最新在实现网关数据集合字符串转换为对象集合的时候报出“com.alibaba.fastjson.JSONException: not match : - =..”异常,详细日志如下所示
com.alibaba.fastjson.JSONException: not match : - =@b@ at com.alibaba.fastjson.parser.JSONLexerBase.nextTokenWithChar(JSONLexerBase.java:387) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.JSONLexerBase.nextTokenWithColon(JSONLexerBase.java:497) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.parseField(JavaBeanDeserializer.java:789) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:596) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:188) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:184) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:726) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:662) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:657) ~[fastjson-1.2.29.jar:?]@b@ at com.alibaba.fastjson.JSON.parseArray(JSON.java:514) ~[fastjson-1.2.29.jar:?]@b@ at com.pingan.bank.cfss.ldsp.dispatchorder.web.TaskSheetController.taskSheetResult(TaskSheetController.java:141) [classes/:?]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_80]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_80]@b@ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_80]@b@ at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_80]@b@ at com.woopa.soofa.annotation.MethodESA.invokeMethod(MethodESA.java:134) @b@ at com.woopa.soofa.annotation.MethodESA.perform(MethodESA.java:45) @b@ at com.woopa.soofa.annotation.MethodESADispatcher._handleRequest(MethodESADispatcher.java:114) @b@ at com.woopa.soofa.annotation.MethodESADispatcher.handleRequest(MethodESADispatcher.java:50) @b@ at com.woopa.soofa.papp.sar.context.DefaultSARDispatcherBean._handleRequest(DefaultSARDispatcherBean.java:118) @b@ at com.woopa.soofa.papp.sar.context.DefaultSARDispatcherBean.handleRequest(DefaultSARDispatcherBean.java:56) @b@ at com.woopa.soofa.papp.sar.SARContextBean.handleRequest(SARContextBean.java:224) @b@ at com.woopa.soofa.papp.context.support.ESAManagerBean.handleInnerRequest(ESAManagerBean.java:205) @b@ at com.woopa.soofa.papp.context.support.ESAManagerBean.handleRequest(ESAManagerBean.java:178) @b@ at com.woopa.soofa.papp.PAppContextBean.handleRequest(PAppContextBean.java:120) @b@ at com.woopa.soofa.papp.protocol.dubbo.ESADubboGenericService.handleAction(ESADubboGenericService.java:52) @b@ at com.woopa.soofa.papp.protocol.dubbo.ESADubboGenericService.$invoke(ESADubboGenericService.java:42) @b@ at com.alibaba.dubbo.common.bytecode.Wrapper1.invokeMethod(Wrapper1.java) [?:2.4.15]@b@ at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:74) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:63) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:112) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52) [dubbo-2.4.15.jar:2.4.15]@b@ at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82) [dubbo-2.4.15.jar:2.4.15]@b@ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_80]@b@ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_80]@b@ at java.lang.Thread.run(Thread.java:745) [?:1.7.0_80]
二、解决方法
1.传过来的字符串格式如下所示
{@b@ id=1,@b@ name=444,@b@ class=class com.woopa.web.form.DataForm,@b@ list=[@b@ { @b@ child_id=123412,@b@ child_name=0@b@ }@b@ ]@b@}
2.最开始写的转换代码如下
List<DataDTO> datalist = JSONArray.parseArray(form.getList(),DataDTO.class);
修改如下即解决问题
String listTxt = JSONArray.toJSONString(form.getList()); @b@List<DataDTO> list = JSONArray.parseArray(listTxt, DataDTO.class);