Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with generic parameters when using fastjson serialization #3779

Closed
2 tasks
kexianjun opened this issue Apr 1, 2019 · 2 comments
Closed
2 tasks

problem with generic parameters when using fastjson serialization #3779

kexianjun opened this issue Apr 1, 2019 · 2 comments
Labels
type/bug Bugs to being fixed

Comments

@kexianjun
Copy link
Member

kexianjun commented Apr 1, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.2
  • Operating System version: windows 10
  • Java version: 1.8

Steps to reproduce this issue

  1. using generic types(say List<PersonTest> or Map<String, List<PersonTest>>) as method parameters
  2. call this RPC method
    the similar problem with generic return type has been fixd in fix fastjson serialization with generic return type #3771

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

the provider side with receive the correct parameter type

Actual Result

the actual result is as the following
image
and when I trying to do some with it, it will throw an exception

If there is an exception, please attach the exception trace:

java.lang.ClassCastException: com.alibaba.fastjson.JSONObject cannot be cast to org.apache.dubbo.demo.PersonTest
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.apache.dubbo.demo.provider.DemoServiceImpl.fastjsonTest1(DemoServiceImpl.java:67)
	at org.apache.dubbo.common.bytecode.Wrapper1.invokeMethod(Wrapper1.java)
	at org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47)
	at org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:86)
	at org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:56)
	at org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
	at org.apache.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:63)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:88)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:54)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:80)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:79)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:137)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:39)
	at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73)
	at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:128)
	at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:103)
	at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:200)
	at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)
	at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
@kexianjun kexianjun changed the title problem with generic parameter when using fastjson serialization problem with generic parameters when using fastjson serialization Apr 1, 2019
@cyejing
Copy link
Contributor

cyejing commented Apr 1, 2019

这个打算怎么修复呢? provide端拿到的参数类型是序列化出来的一层Class https://github.com/apache/incubator-dubbo/blob/1df4a21d315421f0f9f101a6bfd6ab8811853e74/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java#L109

如果可以拿到入参的generic types 就好办了。
还有一种就是开启AutoType的方式,但是希望是服务端和客户端不需要强依赖类型进行序列化。所以才选择用json
你有什么好办法吗?

@lexburner lexburner added bug type/bug Bugs to being fixed and removed bug labels May 14, 2019
@fujinjun
Copy link

fujinjun commented Nov 3, 2020

跟问一下,是怎么解决的?我现在也遇到多层Pojo,无法解析的问题,而且关键在于客户端拿不到原始jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

No branches or pull requests

5 participants