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

nil slice decode to empty slice #317

Closed
mark4z opened this issue Jul 2, 2022 · 2 comments
Closed

nil slice decode to empty slice #317

mark4z opened this issue Jul 2, 2022 · 2 comments

Comments

@mark4z
Copy link
Member

mark4z commented Jul 2, 2022

What happened:
2022/07/02 23:38:21 original struct {"UserFullName":"mark4z","FamilyPhoneNumber":"010-12345678","Slice":null}
2022/07/02 23:38:21 C�com.company.myuser��user_full_name�familyPhoneNumber�slice`�mark4z 010-12345678V�[string�
2022/07/02 23:38:21 decode struct {"UserFullName":"mark4z","FamilyPhoneNumber":"010-12345678","Slice":[]}

What you expected to happen:
nil slice marshal and unMarshal shoulde still equals the 'nil'

How to reproduce it (as minimally and precisely as possible):

type MyUser struct {
	UserFullName      string `hessian:"user_full_name"`
	FamilyPhoneNumber string // default convert to => familyPhoneNumber
	Slice             []string
}

func (MyUser) JavaClassName() string {
	return "com.company.myuser"
}

func main() {
	user := &MyUser{
		UserFullName:      "mark4z",
		FamilyPhoneNumber: "010-12345678",
		Slice:             nil,
	}
	jsonStr, _ := json.Marshal(user)
	log.Printf("original struct %s", jsonStr)
	e := hessian.NewEncoder()
	_ = e.Encode(user)
	buffer := e.Buffer()
	log.Printf("%s", buffer)

	decoder := hessian.NewDecoder(buffer)
	decode, _ := decoder.Decode()
	jsonStr, _ = json.Marshal(decode)
	log.Printf("decode struct %s", jsonStr)
}

Anything else we need to know?:

@mark4z
Copy link
Member Author

mark4z commented Jul 2, 2022

image

@mark4z
Copy link
Member Author

mark4z commented Jul 4, 2022

close via #318

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

1 participant