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

[BUG] omitempty in decoder using ignoreunknowkeys option not working #223

Open
1 task done
ehrktia opened this issue Oct 9, 2024 · 0 comments
Open
1 task done
Labels

Comments

@ehrktia
Copy link

ehrktia commented Oct 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

type A struct{
F1  *int64  `schema:"f1"`
F2  string  `schema:"f2"`
}

the decoder option is set as below

d := schema.NewDecoder()
d.IgnoreUnknownKeys(true)
	if err := d.Decode(inp, v); err != nil {
		return err
	}

schema is decoded successfully but empty values are not omitted.

Expected Behavior

inp := new(A)

got result:

{"f1": 0 , "f2" : " "}

expected

{ }

docs - https://pkg.go.dev/github.com/gorilla/schema#Decoder.IgnoreUnknownKeys
this suggest is similar to encoding/json behaviour when a un known key is encountered it will be skipped and valid keys will still be decoded.
Am i doing something incorrect?
is there any other tag i need to add? like omitempty

Steps To Reproduce

No response

Anything else?

docs - https://pkg.go.dev/github.com/gorilla/schema#Decoder.IgnoreUnknownKeys
this suggest is similar to encoding/json behaviour when a un known key is encountered it will be skipped and valid keys will still be decoded.
Am i doing something incorrect?
is there any other tag i need to add? like omitempty

@ehrktia ehrktia added the bug label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant