Skip to content

Commit 3cc7d0b

Browse files
Patrick KohanPatrick Kohan
authored andcommitted
fix another error when marshalling an empty jsonText
1 parent ae33bab commit 3cc7d0b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

types/types.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ func (g *GzippedText) Scan(src interface{}) error {
4848
// implements `Unmarshal`, which unmarshals the json within to an interface{}
4949
type JsonText json.RawMessage
5050

51-
var _EMPTY_JSON = []byte("{}")
51+
var _EMPTY_JSON = JsonText("{}")
5252

5353
// Returns the *j as the JSON encoding of j.
5454
func (j *JsonText) MarshalJSON() ([]byte, error) {
55+
if len(*j) == 0 {
56+
*j = _EMPTY_JSON
57+
}
5558
return *j, nil
5659
}
5760

@@ -83,7 +86,11 @@ func (j *JsonText) Scan(src interface{}) error {
8386
case string:
8487
source = []byte(t)
8588
case []byte:
86-
source = t
89+
if len(t) == 0 {
90+
source = _EMPTY_JSON
91+
} else {
92+
source = t
93+
}
8794
case nil:
8895
*j = _EMPTY_JSON
8996
default:

0 commit comments

Comments
 (0)