+pkg encoding/json, method (*RawMessage) MarshalJSON() ([]uint8, error)
pkg net, func ListenUnixgram(string, *UnixAddr) (*UDPConn, error)
pkg syscall (darwin-386), func Fchflags(string, int) error
pkg syscall (darwin-386-cgo), func Fchflags(string, int) error
t.Fatal(err)
}
- if want := `{"M":"ImZvbyI="}`; string(b) != want {
+ // Until Go 1.8, this generated `{"M":"ImZvbyI="}`.
+ // See https://github.com/golang/go/issues/14493#issuecomment-255857318
+ if want := `{"M":"foo"}`; string(b) != want {
t.Errorf("Marshal(x) = %#q; want %#q", b, want)
}
}
test(0, 32)
test(math.Copysign(0, -1), 32)
}
+
+func TestMarshalRawMessageValue(t *testing.T) {
+ const val = "\"some value\""
+ b, err := Marshal(RawMessage(val))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if string(b) != val {
+ t.Errorf("got %q; want %q", b, val)
+ }
+}
// be used to delay JSON decoding or precompute a JSON encoding.
type RawMessage []byte
-// MarshalJSON returns *m as the JSON encoding of m.
-func (m *RawMessage) MarshalJSON() ([]byte, error) {
- return *m, nil
+// MarshalJSON returns m as the JSON encoding of m.
+func (m RawMessage) MarshalJSON() ([]byte, error) {
+ return m, nil
}
// UnmarshalJSON sets *m to a copy of data.