alibaba / fastjson2

🚄 FASTJSON2 is a Java JSON library with excellent performance.
Apache License 2.0
3.76k stars 487 forks source link

dubbo使用fastjson2关于autoType对javax.validation影响的问题 #1243

Closed Skqing closed 1 year ago

Skqing commented 1 year ago

请描述您的问题

dubbo使用fastjson2部分接口调用解析异常

版本

dubbo-spring-boot:3.2.0-beta.5

fastjson.version:2.0.25

设置:fastjson.parser.safeMode=true

参考过:https://github.com/alibaba/fastjson2/wiki/fastjson2_autotype_cn fastjson.parser.autoTypeAccept=com.xxx 无效

接口代码:

    BaseResDTO<PayResDTO> queryTicketIncomeAndPay(
            @NotBlank(message = "店铺号不能为空") Integer shopCode
            , @NotNull(message = "开始时间不能为空") Date startTime
            , @NotNull(message = "结束时间不能为空") Date endTime);

异常信息

Caused by: org.apache.dubbo.rpc.RpcException: Failed to invoke the method queryTicketIncomeAndPay in the service com.xxx.client.IShopFeeDetailClient. Tried 3 times of the providers [172.18.0.104:20880] (1/1) from the registry 172.18.0.100:8848 on the consumer 172.18.0.101 using the dubbo version 3.2.0-beta.5. Last error is: Failed to invoke remote method: queryTicketIncomeAndPay, provider: DefaultServiceInstance{serviceName='lot-oto-shop', host='172.18.0.104', port=20880, enabled=true, healthy=true, metadata={dubbo.metadata-service.url-params={"prefer.serialization":"fastjson2,hessian2","cluster":"failfast","loadbalance":"leastactive","timeout":"6000","version":"1.0.0","dubbo":"2.0.2","release":"3.2.0-beta.5","side":"provider","port":"20880","protocol":"dubbo"}, dubbo.endpoints=[{"port":20880,"protocol":"dubbo"}], dubbo.metadata.revision=1bc2b78f8f1a0b8fac46b164efa40410, dubbo.metadata.storage-type=local, timestamp=1678946537496}}, service{name='com.xxx.client.IShopFeeDetailClient',group='null',version='null',protocol='dubbo',port='20880',params={cluster=failfast, executor-management-mode=default, side=provider, release=3.2.0-beta.5, methods=,queryTicketIncomeAndPay, logger=slf4j, deprecated=false, dubbo=2.0.2, loadbalance=leastactive, interface=com.xxx.client.IShopFeeDetailClient, service-name-mapping=true, timeout=6000, generic=false, retries=0, environment=test, delay=2000, application=lot-oto-shop, prefer.serialization=fastjson2,hessian2, background=false, organization=san, file.cache=true, dynamic=true, dump.directory=/home/logs/dubbo, anyhost=true},}, cause: org.apache.dubbo.remoting.RemotingException: com.alibaba.fastjson2.JSONException: autoType not support input javax.validation.UnexpectedTypeException
com.alibaba.fastjson2.JSONException: autoType not support input javax.validation.UnexpectedTypeException
        at com.alibaba.fastjson2.JSONReaderJSONB.checkAutoType(JSONReaderJSONB.java:1136)
        at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:518)
        at org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectInput.readObject(FastJson2ObjectInput.java:114)
        at org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectInput.readObject(FastJson2ObjectInput.java:102)
        at org.apache.dubbo.common.serialize.ObjectInput.readThrowable(ObjectInput.java:74)
        at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.handleException(DecodeableRpcResult.java:171)
        at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.decode(DecodeableRpcResult.java:110)
        at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.decode(DecodeableRpcResult.java:138)
        at org.apache.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:62)
        at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:50)
        at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:62)
        at org.apache.dubbo.common.threadpool.ThreadlessExecutor$RunnableWrapper.run(ThreadlessExecutor.java:184)
        at org.apache.dubbo.common.threadpool.ThreadlessExecutor.waitAndDrain(ThreadlessExecutor.java:103)
        at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:194)
        at org.apache.dubbo.rpc.protocol.AbstractInvoker.waitForResultIfSync(AbstractInvoker.java:285)
        at org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:189)
        at org.apache.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:71)
        at org.apache.dubbo.validation.filter.ValidationFilter.invoke(ValidationFilter.java:98)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.cache.filter.CacheFilter.invoke(CacheFilter.java:95)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:194)
        at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invokeWithContext(AbstractClusterInvoker.java:380)
        at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:81)
        at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:341)
        at org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter.invoke(RouterSnapshotFilter.java:46)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:101)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:52)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.spring.security.filter.ContextHolderParametersSelectedTransferFilter.invoke(ContextHolderParametersSelectedTransferFilter.java:41)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.rpc.cluster.filter.support.ConsumerClassLoaderFilter.invoke(ConsumerClassLoaderFilter.java:40)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter.invoke(ConsumerContextFilter.java:118)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327)
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:194)
        at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$ClusterFilterInvoker.invoke(AbstractCluster.java:92)
        at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:103)
        at org.apache.dubbo.registry.client.migration.MigrationInvoker.invoke(MigrationInvoker.java:282)
        at org.apache.dubbo.rpc.proxy.InvocationUtil.invoke(InvocationUtil.java:56)
        at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:75)
        at com.xxx.client.IShopFeeDetailClientDubboProxy6.queryTicketIncomeAndPay(IShopFeeDetailClientDubboProxy6.java)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
        at jdk.proxy2/jdk.proxy2.$Proxy167.queryTicketIncomeAndPay(Unknown Source)
        at com.san.lot.oto.gateway.controller.shop.SpDataStatController.lambda$query$5(SpDataStatController.java:199)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

        at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:115) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:341) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter.invoke(RouterSnapshotFilter.java:46) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:101) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:52) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.spring.security.filter.ContextHolderParametersSelectedTransferFilter.invoke(ContextHolderParametersSelectedTransferFilter.java:41) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.support.ConsumerClassLoaderFilter.invoke(ConsumerClassLoaderFilter.java:40) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter.invoke(ConsumerContextFilter.java:118) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:327) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:194) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$ClusterFilterInvoker.invoke(AbstractCluster.java:92) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:103) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.registry.client.migration.MigrationInvoker.invoke(MigrationInvoker.java:282) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.proxy.InvocationUtil.invoke(InvocationUtil.java:56) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:75) ~[dubbo-3.2.0-beta.5.jar!/:3.2.0-beta.5]
        at com.xxx.client.IShopFeeDetailClientDubboProxy6.queryTicketIncomeAndPay(IShopFeeDetailClientDubboProxy6.java) ~[shop-client-2.0.0.jar!/:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.25.jar!/:5.3.25]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-5.3.25.jar!/:5.3.25]
        at jdk.proxy2.$Proxy167.queryTicketIncomeAndPay(Unknown Source) ~[?:?]
        at com.xxx.controller.shop.SpDataStatController.lambda$query$5(SpDataStatController.java:199) ~[classes!/:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        ... 1 more
songlongkuan commented 1 year ago

3.2.0 dubbo调用也报这个错误 dubbo接口: @Path("getPerson") String getPerson(@QueryParam("source") String source); 连个String都不能序列化吗

wenshao commented 1 year ago

@songlongkuan song 不要在关闭的issue上反馈问题,新开一个issue,提供相关版本和错误信息。