Skip to content

unexported-serialization-fields

Detect serialization of structs with no exported fields.

Updated View as Markdown

Default severity: warning

The standard JSON and XML packages ignore unexported struct fields. Marshaling a non-empty struct with no exported fields produces empty data, and unmarshaling into it cannot populate anything.

Empty structs, promoted exported fields, and types with custom text, JSON, or XML serialization methods are accepted.

Bad

json.Marshal(struct{ name string }{name: name})

Good

json.Marshal(struct{ Name string }{Name: name})
Navigation

Type to search…

↑↓ navigate↵ selectEsc close