Description
We need a workaround for https://golang.org/issues/11939. Empty structs (full of zeroes) for which ,omitempty is present on all field tags should not show up in MarshalXML output, but they do. See https://play.golang.org/p/J-_l2JySA0 for a trivial example of the problem.
Solution 1: pointers for all
One solution would be to use pointers for everything. However, I don't want to do that, because it makes the resulting types more difficult to use, as each field access will require if v.FieldName != nil { ...
guards.
Solution 2: Smarter MarshalXML methods
Another solution would be to make MarshalXML methods smarter. Ignoring struct embedding which will be gone when #31 is resolved, we can skip emitting the complexType T
if the following conditions are satisfied:
- All of
T
's fields use the,omitempty
option - All of
T
's fields are the zero value for the field's type
The second condition is kind of annoying to check. Something like this would cover most cases:
if (v == T{})
but it won't compile if T
contains a slice, such as with list
types or base64Binary
derivatives.