.UnmarshalJSON()

master
Charles Iliya Krempeaux 2023-09-25 06:59:54 +09:00
parent e38043bd89
commit cb749d3510
1 changed files with 2 additions and 2 deletions

View File

@ -11,10 +11,10 @@ var _ json.Unmarshaler = new(Optional[string])
// UnmarshalJSON makes it so json.Unmarshaler is implemented.
func (receiver *Optional[T]) UnmarshalJSON(data []byte) error {
switch interface{}(receiver.value).(type) {
case bool, string:
case bool, string, json.Unmarshaler:
// these are OK.
default:
return fmt.Errorf("cannot unmarshal into something of type %T from JSON because parameterized type is %T rather than bool or string", receiver, receiver.value)
return fmt.Errorf("cannot unmarshal into something of type %T from JSON because parameterized type is %T rather than bool, string, or json.Unmarshaler", receiver, receiver.value)
}
{