UnmarshalJSON in Int now returns an error message when asked to unmarshal from an invalid type. This is in line with the behavior of the built-in sql.NullInt64.
This commit is contained in:
parent
46b452db55
commit
7cccb14361
3 changed files with 7 additions and 0 deletions
3
bool.go
3
bool.go
|
@ -4,6 +4,7 @@ import (
|
|||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
// "fmt"
|
||||
)
|
||||
|
||||
// Bool is an even nuller nullable bool.
|
||||
|
@ -52,6 +53,8 @@ func (b *Bool) UnmarshalJSON(data []byte) error {
|
|||
case nil:
|
||||
b.Valid = false
|
||||
return nil
|
||||
// default:
|
||||
// err = fmt.Errorf("json: cannot unmarshal %v into Go value of type null.Bool", v.(type).Name())
|
||||
}
|
||||
b.Valid = err == nil
|
||||
return err
|
||||
|
|
BIN
gin-bin
Normal file
BIN
gin-bin
Normal file
Binary file not shown.
4
int.go
4
int.go
|
@ -3,6 +3,8 @@ package null
|
|||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
@ -52,6 +54,8 @@ func (i *Int) UnmarshalJSON(data []byte) error {
|
|||
case nil:
|
||||
i.Valid = false
|
||||
return nil
|
||||
default:
|
||||
err = fmt.Errorf("json: cannot unmarshal %v into Go value of type null.Int", reflect.TypeOf(v).Name())
|
||||
}
|
||||
i.Valid = err == nil
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue