Marshalling null instead of empty slice in Raw().

This commit is contained in:
Victor Starodub
2016-04-14 13:03:15 +03:00
parent dfb1e818b5
commit f6687fef12
+9 -2
View File
@@ -46,10 +46,17 @@ func (w *Writer) RawString(s string) {
// RawByte appends raw binary data to the buffer or sets the error if it is given. Useful for
// calling with results of MarshalJSON-like functions.
func (w *Writer) Raw(data []byte, err error) {
if w.Error == nil && err != nil {
if w.Error != nil {
return
}
switch {
case err != nil:
w.Error = err
} else if w.Error == nil {
case len(data) > 0:
w.Buffer.AppendBytes(data)
default:
w.RawString("null")
}
}