Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NonNullArray ¶
type NonNullArray[T any] []T
NonNullArray is the same type as a slice except that it serializes nil as an empty array when serializing to JSON.
Example ¶
for _, arr := range []NonNullArray[string]{ []string{"a"}, []string{}, nil, } { b, err := json.Marshal(arr) if err != nil { fmt.Println(err) } fmt.Println(string(b)) }
Output: ["a"] [] []
func (NonNullArray[T]) MarshalJSON ¶
func (a NonNullArray[T]) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler
func (*NonNullArray[T]) UnmarshalJSON ¶
func (a *NonNullArray[T]) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler
Click to show internal directories.
Click to hide internal directories.