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

fix: empty slice are set to nil #1702

Merged
merged 1 commit into from Mar 24, 2022
Merged

fix: empty slice are set to nil #1702

merged 1 commit into from Mar 24, 2022

Conversation

aimuz
Copy link
Contributor

@aimuz aimuz commented Mar 24, 2022

support for empty slce, Same behavior as json.Unmarshal

json.Unmarshal

%!p(logic.A={[]})
false
[]

code

type A struct {
	AA []struct {
		C string
	}
}

var c = A{}
reader := io.LimitReader(strings.NewReader(`{"AA":[]}`), 10000)
err = mapping.UnmarshalJsonReader(reader, &c)
if err != nil {
	t.Fatal(err)
}

fmt.Printf("%#p\n", c)
fmt.Println(c.AA == nil)
fmt.Println(c.AA)

before:

%!p(logic.A={[]})
true
[]

after:

%!p(logic.A={[]})
false
[]

support for empty slce, Same behavior as json.Unmarshal
@kevwan kevwan merged commit 70e51bb into zeromicro:master Mar 24, 2022
fynxiu pushed a commit to fynxiu/go-zero that referenced this pull request Apr 1, 2022
support for empty slce, Same behavior as json.Unmarshal
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 this pull request may close these issues.

None yet

2 participants