Skip to content

Commit

Permalink
Merge pull request #4 from lefinal/fix-raw-message-issues
Browse files Browse the repository at this point in the history
fix: raw json raw message treating null as valid again
  • Loading branch information
lefinal authored Jun 20, 2022
2 parents b0ec9be + abee5e9 commit 8374689
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion json_raw_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion json_raw_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8374689

Please sign in to comment.