-
Notifications
You must be signed in to change notification settings - Fork 223
Open
Labels
bugIssues describing a bug in go-toml.Issues describing a bug in go-toml.
Description
Describe the bug
Marshalling netip.Addr with omitempty struct tag always returns empty, because the type doesn't have any exported fields.
To Reproduce
Minimal example:
func TestMarshal(t *testing.T) {
tmp := struct {
IP netip.Addr `toml:"ip,omitempty"`
}{
IP: netip.MustParseAddr("192.168.178.35"),
}
res, err := toml.Marshal(&tmp)
if err != nil {
t.Fatal(err)
}
if string(res) != "ip = '192.168.178.35'\n" {
t.Fatalf("unexpected result: '%s'", res)
}
}
Expected behavior
At the most basic I would expect a struct without any exported fields, but with a MarshalText implementation, to always be marshalled, just to be on the safe side.
Ideally there should be a way to instruct a custom zero behaviour, e.g. netip.Ip already exposes an IsZero() bool
call, so possibly this could be used.
Versions
- go-toml: 2.2.2
- go: 1.22.4
- operating system: Linux
Metadata
Metadata
Assignees
Labels
bugIssues describing a bug in go-toml.Issues describing a bug in go-toml.