apache / dubbo-go

Go Implementation For Apache Dubbo .
https://dubbo.apache.org/
Apache License 2.0
4.69k stars 918 forks source link

复杂类型中支持类型反序列化声明 #1673

Open dongweifly opened 2 years ago

dongweifly commented 2 years ago

go client 调用java provider

Version

go version

dubbo.apache.org/dubbo-go/v3 v3.0.0 github.com/apache/dubbo-go-hessian2 v1.10.0 github.com/dubbogo/grpc-go v1.42.6-tripl

java version

       <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.7.3.5-ext</version>

服务端接口声明

RiskServerResponse<RiskCommonRes> riskEntry(RiskCommonJsonReq req);

调用参数,使用fastJson的JSONObject

public class RiskCommonJsonReq implements Serializable {
    private JSONObject commonParams;
    private JSONObject bizParams;
....
}

GO调用代码

  resp, err := refConf.GetRPCService().(*generic.GenericService).Invoke(
                context.TODO(),
                "riskEntry",
                []string{"common.model.RiskCommonJsonReq"},
                []hessian.Object{
                    map[string]hessian.Object{
                        "bizParams": map[string]hessian.Object{
                            "texts": []hessian.Object{      // 想反序列化得到一个arrayList的对象
                                "微信15245671890",
                            },
                        },
                        "commonParams": map[string]hessian.Object{
                            "code":   "SHOP_INFO_NICKNAME",
                            "ip":     "1.2.3.4",
                            "userId": "12345",
                        },
                    },
                },
            )

如果text 写成[]string, JAVA 端那么序列化出来的类型,String[] 如果text写[]hessian.object,那么JAVA反序列出来的类型Object[], 都不满足服务端的解析要求; 能否提供对arrayList的类型声明支持,或有其他实现路径?

LaurenceLiZhixin commented 2 years ago

cc @sanxun0325

binbin0325 commented 2 years ago

use []*string , such as:

  ss:="微信15245671890"
"texts"=[]*string{&ss}
AlexStocks commented 2 years ago

@dongweifly 如果按照 @sanxun0325 的方法使用后,还有问题,请回复。