Troubleshoot Dubbo serialization Problems

Source: Internet
Author: User
H1. symptom

Added a method for a dubbbo interface:

{Code} domainobject <string> testser (); Implementation: @ override public domainobject <string> testser () {domainobject <string> result = new domainobject <string> (); result. setage (10); result. setname ("test"); result. add ("domainobject1"); return result ;}{ code}

The return value is defined as follows:

{code}public class DomainObject<E> extends ArrayList<E> {    private static final long serialVersionUID = -7393642276493435828L;    private String name;    private int    age;}{code}

Remote Call:

{code}DomainObject<String> result = voucherInfoQueryService.testSer();System.out.println(result.getAge());System.out.println(result.getName());System.out.println(result.get(0));{code}

Output result: the values of the age and name attributes are lost, while the values in the list still exist.

{code}0nullDomainObject1{code}
H1. troubleshooting h4. use Java built-in serialization to execute serialization and deserialization, and the attribute will not be lost. It is suspected that Dubbo serialization has special processing. The default serialization protocol used by h4. Dubbo is hessian2. view the code

The serialization time code is as follows:

{Code} public void writeobject (Object object) throws ioexception {If (Object = NULL) {writenull (); return;} serializer; # Find the corresponding serializer = findserializerfactory (). getserializer (object. getclass (); # serialize serializer. writeobject (object, this) ;}{ code}

Search for serializer: The Code shows that the serializer corresponding to the above domainobject is collectionserializer.

{code}public Serializer getSerializer(Class cl)    throws HessianProtocolException  {  ...   else if (Collection.class.isAssignableFrom(cl)) {      if (_collectionSerializer == null) {_collectionSerializer = new CollectionSerializer();   ...      }{code}

Collectionserializer. writeobject

{code}public void writeObject(Object obj, AbstractHessianOutput out)    throws IOException  {    ...    Iterator iter = list.iterator();    while (iter.hasNext()) {      Object value = iter.next();      out.writeObject(value);    }    ...  }{code}

Therefore, attributes are lost.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.