Conversation
This should not be the case; unlike e.g. encoding/json it should skip empty structs with the omitempty tag; for example: Outputs: The entire situation is a bit unfortunate, as omitempty/omitzero tags have somewhat different meanings than in stdlib (this library goes back to before Go 1.0). I'm not sure what the best solution is 🤔 |
|
Oh so is my understanding that my patch is completely useless and the library already does this? Wow, this is not the first time this happened to me. I can close then. |
|
Not entirely; ideally I would like this to behave identical to stdlib. I'm just not entirely sure what the best path for that is 🤔 I'd like to avoid a v2 if at all possible. Just saying that you shouldn't need this patch for your particular issue. |
|
Okay let me know if you want me to rewrite the patch. |
This patch adds support for
IsZeromethod semantics introduced in Go 1.24 for JSON. When a type has this method implemented asfunc (T) IsZero() booland it returns true and TOML Go structomitzeroexists, the library will omit it completely.This introduces a change, Go built-in type
time.Timealready has this method and previously when an empty time was marshaled it created TOMLtime = 0001-01-01T00:00:00Zwhile now this value is skipped. But this will be only done for those fields which are tagged withomitzerowhich is not an issue, no?Solves: #443
Note this feature does not need Go 1.24, it only follows what Go team is doing for JSON but this will work with any Go version supported by
toml.