aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/stream.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2016-10-31 17:34:42 -0700
committerJoe Tsai <thebrokentoaster@gmail.com>2016-11-01 05:42:33 +0000
commit032d150bd4a812eee9c3ea017f0d3acc8c484325 (patch)
tree0b0fe38fb69f32ea68d6de185417ec585b4ae58e /src/encoding/json/stream.go
parent7a26d9fcedd94a1ba0d95833b0cdbbdcc776fe19 (diff)
downloadgo-032d150bd4a812eee9c3ea017f0d3acc8c484325.tar.xz
encoding/json: marshal with null when RawMessage is nil
This CL expands upon a change made in (http://golang.org/cl/21811) to ensure that a nil RawMessage gets serialized as "null" instead of being a nil slice. The added check only triggers when the RawMessage is nil. We do not handle the case when the RawMessage is non-nil, but empty. Fixes #17704 Updates #14493 Change-Id: I0fbebcdd81f7466c5b78c94953afc897f162ceb4 Reviewed-on: https://go-review.googlesource.com/32472 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/encoding/json/stream.go')
-rw-r--r--src/encoding/json/stream.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/encoding/json/stream.go b/src/encoding/json/stream.go
index 4c350fdd5e..95e30ce36d 100644
--- a/src/encoding/json/stream.go
+++ b/src/encoding/json/stream.go
@@ -248,6 +248,9 @@ type RawMessage []byte
// MarshalJSON returns m as the JSON encoding of m.
func (m RawMessage) MarshalJSON() ([]byte, error) {
+ if m == nil {
+ return []byte("null"), nil
+ }
return m, nil
}