alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.75k stars 6.5k forks source link

fastjson 从1.2.39到1.2.58版本都会遇到List<Map<String, Object>>无法反序列化问题 #2569

Closed danny-zhu closed 5 years ago

danny-zhu commented 5 years ago

服务提供方和调用方都用的dubbo2.6.3进行rpc调用,服务提供方返回结果为 BizResult<List<Map<String, Object>>>,调用方无法反序列化请求结果。调用方的fastjson版本为1.2.39,服务提供方的fastjson版本为1.2.39 (服务提供方的fastjson版本改为1.2.7以后调用方可以正常反序列化,换1.2.58版本也是同样的报错)Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String at com.alibaba.fastjson.JSONObject.put(JSONObject.java:52) 完整报错信息如下: com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method findAccountBy in the service com.xxx.xxx.api.IInvestorService. Tried 2 times of the providers [172.21.1.38:20736] (1/1) from the registry 172.21.10.42:2181 on the consumer 172.21.1.38 using the dubbo version 2.6.3. Last error is: Failed to invoke remote method: findAccountBy, provider: dubbo://172.21.1.38:20736/com.xxx.xxx.api.IInvestorService?anyhost=true&application=evo-service&check=false&dubbo=2.0.2&generic=false&interface=com.xxx.xxx.api.IInvestorService&methods=findIdAndName,budgetReport,isSignContract,findDefaultAccountBy,findAll,findProxyUserEx,findAccountById,findInvestorSettlementMobileBy,fDRecIntfLoan,findAllowedWarehouse,findAccountBy,findProxyUser,closeProductByOrderNo,findCompany,findIdAndNameIncludeSPV&monitor=dubbo%3A%2F%2F172.21.10.42%3A2181%2Fcom.alibaba.dubbo.registry.RegistryService%3Fapplication%3Devo-service%26backup%3D172.21.10.43%3A2181%26dubbo%3D2.0.2%26organization%3Dxxx%26owner%3Dsandi%26pid%3D70164%26protocol%3Dregistry%26refer%3Ddubbo%253D2.0.2%2526interface%253Dcom.alibaba.dubbo.monitor.MonitorService%2526pid%253D70164%2526timestamp%253D1563422122895%26registry%3Dzookeeper%26timestamp%3D1563422122894&organization=xxx&owner=sandi&payload=209715200&pid=70164&register.ip=172.21.1.38&remote.timestamp=1563416525734&retries=1&revision=2.5.3&side=consumer&timeout=8000&timestamp=1563422122842&version=1.0_local, cause: com.alibaba.com.caucho.hessian.io.HessianFieldException: com.xxx.common.entity.BizResult.data: java.lang.Object cannot be assigned from null com.alibaba.com.caucho.hessian.io.HessianFieldException: com.xxx.common.entity.BizResult.data: java.lang.Object cannot be assigned from null at com.alibaba.com.caucho.hessian.io.JavaDeserializer.logDeserializeError(JavaDeserializer.java:173) at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:410) at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:276) at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:203) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2818) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2145) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2118) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074) at com.alibaba.dubbo.common.serialize.hessian2.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:91) at com.alibaba.dubbo.common.serialize.hessian2.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:96) at com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.decode(DecodeableRpcResult.java:111) at com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.decode(DecodeableRpcResult.java:143) at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:92) at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:125) at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:85) at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:46) at com.alibaba.dubbo.remoting.transport.netty.NettyCodecAdapter$InternalDecoder.messageReceived(NettyCodecAdapter.java:133) at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String at com.alibaba.fastjson.JSONObject.put(JSONObject.java:52) at com.alibaba.com.caucho.hessian.io.MapDeserializer.doReadMap(MapDeserializer.java:145) at com.alibaba.com.caucho.hessian.io.MapDeserializer.readMap(MapDeserializer.java:126) at com.alibaba.com.caucho.hessian.io.MapDeserializer.readMap(MapDeserializer.java:98) at com.alibaba.com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java:506) at com.alibaba.com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java:495) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2711) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2278) at com.alibaba.com.caucho.hessian.io.MapDeserializer.doReadMap(MapDeserializer.java:146) at com.alibaba.com.caucho.hessian.io.MapDeserializer.readMap(MapDeserializer.java:126) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2703) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2278) at com.alibaba.com.caucho.hessian.io.CollectionDeserializer.readLengthList(CollectionDeserializer.java:122) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2672) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2278) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2080) at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074) at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:406) ... 31 more

danny-zhu commented 5 years ago

resources目录下增加fastjson.properties文件 增加内容: parser.features.NonStringKeyAsString=true 即可解决

类似的问题参考 #2572