Euraxluo opened a new issue #262:
URL: https://github.com/apache/dubbo-go-hessian2/issues/262


   <!-- Please use this template while reporting a bug and provide as much info 
as possible. Not doing so may result in your bug not being addressed in a 
timely manner. Thanks!
   
   -->
   
   
   **What happened**:
   go-mod:
   ```
   require (
        github.com/apache/dubbo-go v1.5.5
        github.com/apache/dubbo-go-hessian2 v1.8.2
        github.com/dubbogo/gost v1.9.5
   )
   ```
   当我使用以上版本进行和java 
dubbo进行通信时,发现复杂嵌套对象的序列化会出错,会把List<UserVo>序列化为List<HashMap>,导致服务端代码运行失败
   
   **What you expected to happen**:
   错误的序列化,导致实体类中的某些方法无法被调用
   
   
   **How to reproduce it (as minimally and precisely as possible)**:
   server
   ```java
   //interface
   public interface UserProvider {
       void collectionUser(Page<UserVo> pageUserVo);
   }
   //impl
   public class UserProviderImpl implements UserProvider {
       public void collectionUser(Page<UserVo> pageUserVo ){
           List<UserVo> userVoList =  pageUserVo.getData();
           UserVo userVo = (UserVo) userVoList.toArray()[0];
           return;
       }
   }
   
   //pojo Page
   public class Page<T> implements Serializable {
       private static final long serialVersionUID = 1L;
       private List<T> data;
   
       public Page() {
       }
       public Page( List<T> data) {
           this.data = data;
       }
       public List<T> getData() {
           return this.data;
       }
   
       public void setData(List<T> data) {
           this.data = data;
       }
   }
   //pojo UserVo
   public class UserVo implements Serializable {
       private User user;
       public UserVo(User user) { this.user = user; }
       public UserVo() { }
       public User getUser() {
           return user;
       }
       public void setUser(User user) {
           this.user = user;
       }
   }
   ```
   client_main.go
   ```go
   var (
        appName         = "UserProviderGer"
        referenceConfig = config.ReferenceConfig{
                Registry:      "demoZk",
                InterfaceName: "com.dml_express.dubbo_test.UserProvider",
                Cluster:       "failover",
                Protocol:      dubbo.DUBBO,
                Generic:       true,
        }
   )
   
   func init() {
        hessian.RegisterPOJO(&pkg.User{})
        hessian.RegisterPOJO(&pkg.UserVo{})
        hessian.RegisterPOJO(&pkg.UserVos{})
        referenceConfig.GenericLoad(appName)
   }
   func main() {
   collectionUser()
   }
   func collectionUser() {
        genericService := 
referenceConfig.GetRPCService().(*config.GenericService)
        page :=pkg.Page{
                Data: []pkg.UserVo{
                        pkg.UserVo{
                                User: pkg.User{
                                        Id:   "1000",
                                        Name: "user_name",
                                        Age:  2,
                                        Time: time.Now(),
                                },
                        },
                        pkg.UserVo{
                                User: pkg.User{
                                        Id:   "1000",
                                        Name: "user_name",
                                        Age:  2,
                                        Time: time.Now(),
                                },
                        },
                },
        }
        resp, err := genericService.Invoke(context.TODO(),
                []interface{}{"collectionUser",
                        []string{"com.dml_express.dubbo_test.Page"},
                        []interface{}{page}})
   
        if err != nil {
                gxlog.CError("error: %v\n", err)
                os.Exit(1)
                return
        }
        gxlog.CInfo("response result: %v\n", resp)
   }
   
   ```
   pkg.user.go
   ```go
   type User struct {
        Id   string
        Name string
        Age  int32
        Time time.Time
   }
   func (User) JavaClassName() string {
        return "com.dml_express.dubbo_test.User"
   }
   type UserVo struct{
        User  User
   }
   func (UserVo) JavaClassName() string {
        return "com.dml_express.dubbo_test.UserVo"
   }
   
   type Page struct {
        Data []UserVo `hessian:"data"`
   }
   func (Page) JavaClassName() string {
        return "com.dml_express.dubbo_test.Page"
   }
   ```
   **Anything else we need to know?**:
   当我调用时,会报以下错误在java端impl中
   ` error: java.lang.ClassCastException: java.util.HashMap cannot be cast to 
com.dml_express.dubbo_test.UserVo
   `
   
   一些其他的图片:
   go调用java
   
![image-20210312142331445](https://gitee.com/Euraxluo/images/raw/master/picgo/image-20210312142331445.png)
   
   java互相调用:
   
![image-20210312143218876](https://gitee.com/Euraxluo/images/raw/master/picgo/image-20210312143218876.png)
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to