Skip to content

Create slice/map/string fields without pointers (for optional fields) #266

@v-byte-cpu

Description

@v-byte-cpu

Default value for slice/map is nil. So slice/map field will not be serialized if it is not initialized.

I mean from serialization point of view these two structs are the same:

struct {
  GroupKey *[]string `json:"group_key,omitempty"`
}
struct {
  GroupKey []string `json:"group_key,omitempty"`
}

The later version is more convenient to work with..

https://play.golang.org/p/0c0nVaoOPNK

Also the same applies to string type with omitempty json tag.

Pointer to interface *interface{} struct fields are also useless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions