You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stbenjam
changed the title
encoding/xml: cannot mark nested element as omitempty
encoding/xml: cannot mark parent of nested element omitempty
Jan 20, 2023
Might it be worth adding some clarity to the documentation that modifiers like omitempty or any are only allowed at the end of a struct tag, not interwoven with nested tags in the XML case?
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Trying to marshal/unmarshal junit XML testsuites. I cannot get omitempty to work on the parent of a potentially nested field.
For this example XML:
If there is no properties element, like this:
I would like properties to NOT be marshalled.
Example: https://go.dev/play/p/iYsJBSIKAQl
I tried to put omitempty in two different ways:
and
The former does not work for
properties
, the latter is invalid because>
is split after splitting on,
(https://cs.opensource.google/go/go/+/refs/tags/go1.19.5:src/encoding/xml/typeinfo.go;l=113)What did you expect to see?
I expected
<properties></properties>
to not be in the marshalled output when specifyingomitempty
What did you see instead?
It was included.
The text was updated successfully, but these errors were encountered: