jsonext

package
v0.0.0-...-e338c6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 1 Imported by: 0

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL