package utils import "encoding/json" type Optional[T any] struct { explicit bool hasValue bool value T } func (o *Optional[T]) UnmarshalJSON(b []byte) error { if len(b) == 0 { return nil } o.explicit = true if string(b) == "null" { return nil } o.hasValue = true return json.Unmarshal(b, &o.value) } func (o *Optional[T]) Explicit() bool { return o.explicit } func (o *Optional[T]) Value() *T { if !o.explicit || !o.hasValue { return nil } return &o.value }