From 3487d45a26cfa5747086d688c6e6926a3ecbf572 Mon Sep 17 00:00:00 2001 From: Lucas Rouckhout Date: Tue, 4 May 2021 19:26:17 +0200 Subject: [PATCH] Adjust JSON unmarshalling to inherit from a bool instead of using a blank interface. --- bool.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/bool.go b/bool.go index 0e1fc96..463ccb5 100644 --- a/bool.go +++ b/bool.go @@ -4,8 +4,6 @@ package abool import ( "encoding/json" - "errors" - "fmt" "sync/atomic" ) @@ -82,16 +80,11 @@ func (ab *AtomicBool) MarshalJSON() ([]byte, error) { // Unmarshall normal bool's into AtomicBool func (ab *AtomicBool) UnmarshalJSON(b []byte) error { - var v interface{} + var v bool if err := json.Unmarshal(b, &v); err != nil { return err } - switch value := v.(type) { - case bool: - ab.SetTo(value) - return nil - default: - return errors.New(fmt.Sprintf("%s is an invalid JSON representation for an AtomicBool\n", b)) - } + ab.SetTo(v) + return nil }