.MarshalJSON()

master
Charles Iliya Krempeaux 2023-09-25 11:35:13 +09:00
parent d6b2890eaa
commit 3e7cdb405e
1 changed files with 1 additions and 1 deletions

View File

@ -11,7 +11,7 @@ var _ json.Marshaler = Nothing[string]()
// MarshalJSON makes it so json.Marshaler is implemented. // MarshalJSON makes it so json.Marshaler is implemented.
func (receiver Optional[T]) MarshalJSON() ([]byte, error) { func (receiver Optional[T]) MarshalJSON() ([]byte, error) {
switch interface{}(receiver.value).(type) { switch interface{}(receiver.value).(type) {
case bool, string: case bool, string, json.Marshaler:
// these are OK. // these are OK.
default: default:
return nil, fmt.Errorf("cannot marshal something of type %T into JSON because parameterized type is %T rather than bool or string", receiver, receiver.value) return nil, fmt.Errorf("cannot marshal something of type %T into JSON because parameterized type is %T rather than bool or string", receiver, receiver.value)