Skip to content

Commit b0ec1bd

Browse files
committed
Don't marshal empty byte or uint8 slice as null
[]byte or []uint8 are encoded as base-64 encoded string. Per this, non-nil empty slice should not get marshalled as null, rather as "". This restores compatibility with the standard library.
1 parent 08047c1 commit b0ec1bd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

reflect_native.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
432432
}
433433

434434
func (codec *base64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
435-
src := *((*[]byte)(ptr))
436-
if len(src) == 0 {
435+
if codec.sliceType.UnsafeIsNil(ptr) {
437436
stream.WriteNil()
438437
return
439438
}
439+
src := *((*[]byte)(ptr))
440440
encoding := base64.StdEncoding
441441
stream.writeByte('"')
442442
size := encoding.EncodedLen(len(src))

0 commit comments

Comments
 (0)