.MarshalJSON()
parent
d6b2890eaa
commit
3e7cdb405e
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue