Skip to content

Commit

Permalink
fix #291 omit empty was not handled properly for json raw message
Browse files Browse the repository at this point in the history
  • Loading branch information
taowen committed Aug 6, 2018
1 parent 0260c89 commit 5d789e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (cfg *frozenConfig) validateJsonRawMessage(extension EncoderExtension) {
stream.WriteRaw(string(rawMessage))
}
}, func(ptr unsafe.Pointer) bool {
return false
return len(*((*json.RawMessage)(ptr))) == 0
}}
extension[reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()] = encoder
extension[reflect2.TypeOfPtr((*RawMessage)(nil)).Elem()] = encoder
Expand Down
10 changes: 9 additions & 1 deletion value_tests/raw_message_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package test

import "encoding/json"
import (
"encoding/json"
)

func init() {
marshalCases = append(marshalCases,
json.RawMessage("{}"),
selectedMarshalCase{struct {
Env string `json:"env"`
Extra json.RawMessage `json:"extra,omitempty"`
}{
Env: "jfdk",
}},
)
unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*json.RawMessage)(nil),
Expand Down

0 comments on commit 5d789e5

Please sign in to comment.