You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by Daniel SAWAN <da...@gmail.com> on 2022/04/08 15:20:07 UTC

Problem with List param (dubbo version: 2.7.15)

Hello,

I have a method on a dubbo server :

public void test(List<User> users);

when i call it from dubbo client i got 2 errors:

server side error :
java.lang.ClassCastException: class com.alibaba.fastjson.JSONObject cannot
be cast to class models.User (com.alibaba.fastjson.JSONObject and
models.User are in unnamed module of loader java.net.URLClassLoader
@14f3c6fc)

client side error :
Caused by: org.apache.dubbo.remoting.RemotingException:
com.alibaba.fastjson.JSONException: autoType is not support.
java.lang.ClassCastException

Seems like instead of sending a List<User> dubbo client is sending a
List<JSONObject> to Dubbo server.

If someone knows the reason...

Thanks for your help !

Re: Problem with List param (dubbo version: 2.7.15)

Posted by Daniel SAWAN <da...@gmail.com>.
After some google search about this problem i saw a github issue with a
developper having the same problem

https://github.com/apache/dubbo/issues/3779

From what I understand this issue has been fixed so for which reason do you
guys think i still have the problem ?

Thanks for your help !

Le jeu. 14 avr. 2022 à 16:01, Daniel SAWAN <da...@gmail.com> a écrit :

> I am using fastjson without importing the
> maven dubbo-serialization-fastjson pom. Seems like it is included in Dubbo.
>
> My consumer url is
> : reference.setUrl("dubbo://"+vpsIp+":20880/"+interfaceName+"?token=1234567&serialization=fastjson");
>
> So as you can see i put the serialization directly in the URL because i
> didn't find a way to configure it in java. (if you can help on this...)
>
> "I think the the exception happened on the provider side when trying to
> deserialize raw json data to java bean."
> That's exactly what is happening.
>
> "FastjsonObjectInput#readObject(Class<T> cls, Type type)"
>
> This method is never called. The called method is "public <T> T
> readObject(Class<T> cls)"
>
> here is some screenshots to show you what is happening :
>
> https://i.imgur.com/VAdQKlt.png
> https://i.imgur.com/5su4FsJ.png
>
> and finally when the error happen : https://i.imgur.com/66zfbUi.png
>
> So yes it seems like when using fastjson it got a Map of JSONObject
> instead of a List of OperatingSystemVersion.
> If i remove from the consumer url the param serialization=fastjson
> everything work fine.
>
>
>
>
>
>
> Le jeu. 14 avr. 2022 à 15:11, Jun Liu <li...@apache.org> a écrit :
>
>> Are you using fastjson as the default serialization protocol there? Say
>> by using ‘dubbo-serialization-fastjson’?
>>
>> I think the the exception happened on the provider side when trying to
>> deserialize raw json data to java bean. Would you please set a breakpoint
>> at the following place to try to debug and see the exact type of the second
>> argument ’type’?
>>
>>   FastjsonObjectInput#readObject(Class<T> cls, Type type)
>>
>> I guess it’s because the autoType feature has been disabled in the latest
>> several fastjson releases for security reasons.
>>
>> Jun
>>
>> > On Apr 8, 2022, at 11:20 PM, Daniel SAWAN <da...@gmail.com>
>> wrote:
>> >
>> > client side error :
>> > Caused by: org.apache.dubbo.remoting.RemotingException:
>> > com.alibaba.fastjson.JSONException: autoType is not support.
>> > java.lang.ClassCastException
>> >
>> > Seems like instead of sending a List<User> dubbo client is sending a
>> > List<JSONObject> to Dubbo server.
>>
>>

Re: Problem with List param (dubbo version: 2.7.15)

Posted by Daniel SAWAN <da...@gmail.com>.
I am using fastjson without importing the
maven dubbo-serialization-fastjson pom. Seems like it is included in Dubbo.

My consumer url is
: reference.setUrl("dubbo://"+vpsIp+":20880/"+interfaceName+"?token=1234567&serialization=fastjson");

So as you can see i put the serialization directly in the URL because i
didn't find a way to configure it in java. (if you can help on this...)

"I think the the exception happened on the provider side when trying to
deserialize raw json data to java bean."
That's exactly what is happening.

"FastjsonObjectInput#readObject(Class<T> cls, Type type)"

This method is never called. The called method is "public <T> T
readObject(Class<T> cls)"

here is some screenshots to show you what is happening :

https://i.imgur.com/VAdQKlt.png
https://i.imgur.com/5su4FsJ.png

and finally when the error happen : https://i.imgur.com/66zfbUi.png

So yes it seems like when using fastjson it got a Map of JSONObject instead
of a List of OperatingSystemVersion.
If i remove from the consumer url the param serialization=fastjson
everything work fine.






Le jeu. 14 avr. 2022 à 15:11, Jun Liu <li...@apache.org> a écrit :

> Are you using fastjson as the default serialization protocol there? Say by
> using ‘dubbo-serialization-fastjson’?
>
> I think the the exception happened on the provider side when trying to
> deserialize raw json data to java bean. Would you please set a breakpoint
> at the following place to try to debug and see the exact type of the second
> argument ’type’?
>
>   FastjsonObjectInput#readObject(Class<T> cls, Type type)
>
> I guess it’s because the autoType feature has been disabled in the latest
> several fastjson releases for security reasons.
>
> Jun
>
> > On Apr 8, 2022, at 11:20 PM, Daniel SAWAN <da...@gmail.com> wrote:
> >
> > client side error :
> > Caused by: org.apache.dubbo.remoting.RemotingException:
> > com.alibaba.fastjson.JSONException: autoType is not support.
> > java.lang.ClassCastException
> >
> > Seems like instead of sending a List<User> dubbo client is sending a
> > List<JSONObject> to Dubbo server.
>
>

Re: Problem with List param (dubbo version: 2.7.15)

Posted by Jun Liu <li...@apache.org>.
Are you using fastjson as the default serialization protocol there? Say by using ‘dubbo-serialization-fastjson’?

I think the the exception happened on the provider side when trying to deserialize raw json data to java bean. Would you please set a breakpoint at the following place to try to debug and see the exact type of the second argument ’type’?

  FastjsonObjectInput#readObject(Class<T> cls, Type type) 

I guess it’s because the autoType feature has been disabled in the latest several fastjson releases for security reasons. 

Jun

> On Apr 8, 2022, at 11:20 PM, Daniel SAWAN <da...@gmail.com> wrote:
> 
> client side error :
> Caused by: org.apache.dubbo.remoting.RemotingException:
> com.alibaba.fastjson.JSONException: autoType is not support.
> java.lang.ClassCastException
> 
> Seems like instead of sending a List<User> dubbo client is sending a
> List<JSONObject> to Dubbo server.


Re: Problem with List param (dubbo version: 2.7.15)

Posted by Daniel SAWAN <da...@gmail.com>.
Hi it is me again.
Nobody has a solution ? It is a simple use case to reproduce.

Le ven. 8 avr. 2022 à 17:20, Daniel SAWAN <da...@gmail.com> a écrit :

> Hello,
>
> I have a method on a dubbo server :
>
> public void test(List<User> users);
>
> when i call it from dubbo client i got 2 errors:
>
> server side error :
> java.lang.ClassCastException: class com.alibaba.fastjson.JSONObject cannot
> be cast to class models.User (com.alibaba.fastjson.JSONObject and
> models.User are in unnamed module of loader java.net.URLClassLoader
> @14f3c6fc)
>
> client side error :
> Caused by: org.apache.dubbo.remoting.RemotingException:
> com.alibaba.fastjson.JSONException: autoType is not support.
> java.lang.ClassCastException
>
> Seems like instead of sending a List<User> dubbo client is sending a
> List<JSONObject> to Dubbo server.
>
> If someone knows the reason...
>
> Thanks for your help !
>