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

两个Map结构不同但值为nil时,decode will panic #356

Closed
KellendF opened this issue Mar 31, 2023 · 0 comments · Fixed by #357
Closed

两个Map结构不同但值为nil时,decode will panic #356

KellendF opened this issue Mar 31, 2023 · 0 comments · Fixed by #357

Comments

@KellendF
Copy link

What happened:
两个Map结构不同但值为nil时,decode will panic
What you expected to happen:
返回空Map
How to reproduce it (as minimally and precisely as possible):

type UserInfo struct {
	Name    string
	Address map[string]string
	Family  map[string]int
}

func (UserInfo) JavaClassName() string {
	return "com.test.ReqInfo"
}

func TestIssueCase(t *testing.T) {
	req := &UserInfo{
		Name:    "test",
		Address: nil,
		Family:  nil,
	}

	hessian.RegisterPOJO(req)

	encoder := hessian.NewEncoder()
	err := encoder.Encode(req)
	if err != nil {
		t.Error(err)
		return
	}

	enBuf := encoder.Buffer()

	decoder := hessian.NewDecoder(enBuf)
	deReq, err := decoder.Decode()
	assert.Nil(t, err)

	t.Log(deReq)

	assert.True(t, reflect.DeepEqual(req, deReq))
}

=== RUN   TestIssueCase
--- FAIL: TestIssueCase (0.00s)
panic: reflect.Set: value of type map[string]string is not assignable to type map[string]int [recovered]
	panic: reflect.Set: value of type map[string]string is not assignable to type map[string]int

Anything else we need to know?:

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

Successfully merging a pull request may close this issue.

1 participant