Skip to content

Commit

Permalink
Don't marshal empty byte or uint8 slice as null
Browse files Browse the repository at this point in the history
[]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.
  • Loading branch information
nikhita committed Jun 2, 2019
1 parent 08047c1 commit b0ec1bd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions reflect_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
}

func (codec *base64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
src := *((*[]byte)(ptr))
if len(src) == 0 {
if codec.sliceType.UnsafeIsNil(ptr) {
stream.WriteNil()
return
}
src := *((*[]byte)(ptr))
encoding := base64.StdEncoding
stream.writeByte('"')
size := encoding.EncodedLen(len(src))
Expand Down

0 comments on commit b0ec1bd

Please sign in to comment.