Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

decode do not zero the field #299

Open
cuiweixie opened this issue Aug 10, 2022 · 0 comments
Open

decode do not zero the field #299

cuiweixie opened this issue Aug 10, 2022 · 0 comments

Comments

@cuiweixie
Copy link

cuiweixie commented Aug 10, 2022

func TestIssue299(t *testing.T) {
var a []interface{}
inputStringSlice := map[string]interface{}{
"vfoo": "foo",
"vbar": a,
}
var result = Slice{
Vfoo: "a",
Vbar: []string{"a", "b"},
}
config := &DecoderConfig{
Metadata: nil,
ZeroFields: true,
Result: &result,
WeaklyTypedInput: true,
}

decoder, err := NewDecoder(config)
if err != nil {
	t.Fatalf("got error: %s", err)
}

err = decoder.Decode(inputStringSlice)
if err != nil {
	t.Fatalf("got error: %s", err)
}
if result.Vfoo != "foo" {
	t.Errorf("want want get %s", result.Vfoo)
}
if len(result.Vbar) != 0 {
	t.Errorf("want len(result.Vbar) == 0, get %d", len(result.Vbar))
}

}

this will failed

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

No branches or pull requests

1 participant