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

go-hessian2报错 error:decObject illegal object type tag:121 #220

Closed
jjhewlett opened this issue Aug 17, 2020 · 22 comments
Closed

go-hessian2报错 error:decObject illegal object type tag:121 #220

jjhewlett opened this issue Aug 17, 2020 · 22 comments

Comments

@jjhewlett
Copy link

go-hessian2报错 error:decObject illegal object type tag:121

我是Java服务端,dubbo-go是客户端。
现在Data是java下发的一个List,list里每一个元素,都是实体对象
下发单个没问题,下发list的就go-hessian2抛异常

hessian.RegisterPOJO(&ResponseData{})
type ResponseData struct {
Code string
Msg string
Data interface{}
}

@wongoo
Copy link
Contributor

wongoo commented Aug 17, 2020

there should be a JavaClassName() func for the struct.

@jjhewlett
Copy link
Author

@wongoo 我都已经设置好了的。
GetOrder这个方法返回的是一个order list
GetOrderOne 返回的是一个order object
响应的数据结构都是ResponseData
image

@wongoo
Copy link
Contributor

wongoo commented Aug 18, 2020

@jjhewlett more details needed, include java object definition, java test data, code sample. And I guess, u only register ResponseData, but not for order object. u need register all objects.

@jjhewlett
Copy link
Author

@wongoo 这个是JAVA服务端的代码,现在getOrderOne是可以正常返回的。
image

@jjhewlett
Copy link
Author

@wongoo 我在Go语言的客户端已经注册了order的结构体了

@wongoo
Copy link
Contributor

wongoo commented Aug 18, 2020

glad to hear that, and u can post how that you resolve your problem, maybe it's useful for others.

@jjhewlett
Copy link
Author

@wongoo
目前还没有解决这个问题,我目前也很苦恼
在JAVA服务层,我的DATA是个泛型。
我尝试过go客户端的response data改成[]interface{},但是改成这样我的详情就直接抛相同的异常了。

@wongoo
Copy link
Contributor

wongoo commented Aug 18, 2020

@jjhewlett u can create a test case so that we can work on it, ref the example as follow:

public void customReplyPerson183() throws Exception {

got, err := decodeJavaResponse(`customReplyPerson183`, ``, false)

@jjhewlett
Copy link
Author

@wongoo 好的,我先看下测试用例。真的万分感谢。

@jjhewlett
Copy link
Author

@wongoo 您好。看了下pojo.go的代码,
好像是一个JavaClassName 对应一个goName。
不知道可不可以实现多个JavaClassName 对应一个goName呢

@wongoo
Copy link
Contributor

wongoo commented Aug 18, 2020

not support now, u can create a new struct extending the exist one and overwrite the JavaClassName func

@jjhewlett
Copy link
Author

OK,我试下继承重写。要是GO支持泛型就没那么麻烦了。

@jjhewlett
Copy link
Author

@wongoo 万分感谢

@jjhewlett
Copy link
Author

@wongoo 你好,
服务端返回的是一个map.
map有2个key,一个key是int,一个key是list
该如何定义。才能够正常解析。

@AlexStocks
Copy link
Contributor

@jjhewlett why u define so complicated map?

@wongoo
Copy link
Contributor

wongoo commented Aug 18, 2020

@jjhewlett 你最好按照上面我给你的例子写一个test case,把问题模拟出来,这样才好分析问题出在哪里。 比如这个issue #214 就是一个很好的例子。

@jjhewlett
Copy link
Author

jjhewlett commented Aug 18, 2020

@wongoo 目前data没有被解析出来
image

import (
	hessian "github.com/apache/dubbo-go-hessian2"
	"fmt"
)

type ResponseData struct {
	Code string
	Msg  string
	Data map[string]interface{}
}


func (ResponseData) JavaClassName() string {
	return "com.example.dubbo_tools.domain.ResponseData"
}

func main() {
	res := &ResponseData{}
	res.Code = "0000"
	res.Msg = "成功"

	list := []string{"A","B","C"}
	data := map[string]interface{}{
		"count" : 1,
		"data"  : list,
	}
	res.Data = data

	e := hessian.NewEncoder()
	err := e.Encode(res)
	if err != nil {
		panic(err)
	}
	bytes := e.Buffer()
	decoder := hessian.NewDecoder(bytes)
	decode, err := decoder.Decode()
	if err != nil {
		panic(err)
	}
	fmt.Println(decode)
}

@jjhewlett
Copy link
Author

非常感谢 @wongoo @AlexStocks 这两位大神的技术支持。现在已经和JAVA端通信成功了。
因为Golang语法不支持泛型。已经将代码改成如下
image
返回结果:
image

@AlexStocks
Copy link
Contributor

@jjhewlett u r welcome. Would u help us to register ur com/org info into apache/dubbo-go#2? thank u so much.

@jjhewlett
Copy link
Author

@AlexStocks 非常感谢您的邀请,目前我们公司还是以JAVA为主。以后我有新的机会的时候会尝试dubbo-go。

@milerL
Copy link

milerL commented Oct 9, 2020

@AlexStocks 非常感谢您的邀请,目前我们公司还是以JAVA为主。以后我有新的机会的时候会尝试dubbo-go。

go的客户端 strcut 看着好奇怪啊。。能看一下你的ResponseData Struct 吗

@milerL
Copy link

milerL commented Oct 10, 2020

@jjhewlett 打扰了 问一下你们有没有遇到过
外面用Response包了一层 然后Response里面有个result 字段返回 结构体或者int 这种情况

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants