From abee5e9813aa19a0dcce862bf97cc3fc6d69b423 Mon Sep 17 00:00:00 2001 From: Lennart Altenhof Date: Mon, 20 Jun 2022 13:32:46 +0200 Subject: [PATCH] fix: raw json raw message treating null as valid again --- json_raw_message.go | 2 +- json_raw_message_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/json_raw_message.go b/json_raw_message.go index e2b408f..d213be2 100644 --- a/json_raw_message.go +++ b/json_raw_message.go @@ -35,7 +35,7 @@ func (rm JSONRawMessage) MarshalJSON() ([]byte, error) { // UnmarshalJSON as json.RawMessage or sets Valid to false if empty. func (rm *JSONRawMessage) UnmarshalJSON(data []byte) error { // Do NOT use regular NULL-check here. - if data == nil { + if isNull(data) { rm.Valid = false rm.RawMessage = nil return nil diff --git a/json_raw_message_test.go b/json_raw_message_test.go index fd565d1..e602db8 100644 --- a/json_raw_message_test.go +++ b/json_raw_message_test.go @@ -73,7 +73,7 @@ func (suite *JSONRawMessageUnmarshalJSONSuite) TestNull() { } err := json.Unmarshal([]byte(`{"rm": null}`), &s) suite.Require().NoError(err, "should not fail") - suite.True(s.RM.Valid, "should not be valid") + suite.False(s.RM.Valid, "should not be valid") } func (suite *JSONRawMessageUnmarshalJSONSuite) TestOK() {