Skip to content

encoding/xml: inconsistent omitempty compared to encoding/json #5452

Closed
@gopherbot

Description

@gopherbot

by krolaw:

Both packages define empty as being:
"The empty values are false, 0, any nil pointer or interface value, and any array,
slice, map, or string of length zero."

However, json does not look at the value behind pointers, while xml does.  This
difference is made obvious when wanting to omit nil pointers, but retain empty values.

Without omitempty:
xml will omit tags with nil pointers (not documented)
json will display null for nil pointers.

With omitempty:
xml will omit pointer fields pointing to empty values.
json will DISPLAY pointer fields pointing to empty values.

My current solution is: have omitempty on for json and off for xml.

http://play.golang.org/p/hANosIIkM_

This is probably a documentation issue.  If it's a bug, please retain ability to omit
nil pointers, but not look at values beyond the pointer. 

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions