Skip to content

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

Open
@ehrktia

Description

@ehrktia

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions