struct
parent
73f29b1d15
commit
fc545108d9
|
@ -2,6 +2,7 @@ package nul
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
"github.com/reiver/go-erorr"
|
||||
)
|
||||
|
@ -15,7 +16,9 @@ func (receiver Nullable[T]) MarshalJSON() ([]byte, error) {
|
|||
case bool, string,json.Marshaler:
|
||||
// these are OK.
|
||||
default:
|
||||
return nil, erorr.Errorf("nul: cannot marshal something of type %T into JSON because parameterized type is ‘%T’ rather than ‘bool’, ‘string’, or ‘json.Marshaler’", receiver, receiver.value)
|
||||
if reflect.Struct != reflect.TypeOf(receiver.value).Kind() {
|
||||
return nil, erorr.Errorf("nul: cannot marshal something of type %T into JSON because parameterized type is ‘%T’ rather than ‘bool’, ‘string’, or ‘json.Marshaler’", receiver, receiver.value)
|
||||
}
|
||||
}
|
||||
|
||||
if receiver.isnothing() {
|
||||
|
|
|
@ -2,6 +2,7 @@ package nul
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
"github.com/reiver/go-erorr"
|
||||
)
|
||||
|
@ -21,7 +22,9 @@ func (receiver *Nullable[T]) UnmarshalJSON(data []byte) error {
|
|||
case bool,string,json.Unmarshaler:
|
||||
// these are OK.
|
||||
default:
|
||||
return erorr.Errorf("nul: cannot unmarshal into something of type %T from JSON because parameterized type is ‘%T’ rather than ‘bool’, ‘string’, or ‘json.Unmarshaler’", receiver, receiver.value)
|
||||
if reflect.Struct != reflect.TypeOf(receiver.value).Kind() {
|
||||
return erorr.Errorf("nul: cannot unmarshal into something of type %T from JSON because parameterized type is ‘%T’ rather than ‘bool’, ‘string’, or ‘json.Unmarshaler’", receiver, receiver.value)
|
||||
}
|
||||
}
|
||||
|
||||
if 4 == len(data) && 'n' == data[0] && 'u' == data[1] && 'l' == data[2] && 'l' == data[3] {
|
||||
|
|
Loading…
Reference in New Issue