Documentation
¶
Overview ¶
Package optional provides a generic type that can represent values which may or may not be set, including the concept of null. This allows handling scenarios where a value might be missing or explicitly set to null in JSON.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeMarshal ¶
ChangeMarshal allows you to change the function used for marshalling. By default, it uses json.Marshal. You can provide an alternative implementation, such as from a library like https://pkg.go.dev/github.com/json-iterator/go.
func ChangeUnmarshal ¶
ChangeUnmarshal allows you to change the function used for unmarshalling. By default, it uses json.Unmarshal. You can provide an alternative implementation, such as from a library like https://pkg.go.dev/github.com/json-iterator/go.
Types ¶
type Type ¶
type Type[T any] struct { V T // V holds the actual value of type T. // contains filtered or unexported fields }
Type represents a generic value that may or may not be set and could also be null.
func (Type[T]) IsSet ¶
IsSet checks if the value has been set, either to a non-null value or explicitly to null.
func (Type[T]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for Type. It handles marshalling a Type instance to JSON, correctly representing unset values as empty, null values as `null`, and non-null values using the specified marshaller.
func (*Type[T]) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for Type. It handles unmarshalling JSON data into a Type instance, distinguishing between unset values, null values, and actual non-null values.