File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,11 @@ func Test_map_eface_of_eface(t *testing.T) {
4242 should .NoError (err )
4343 should .Equal (`{"1":2,"3":"4"}` , output )
4444}
45+
46+ func Test_encode_nil_map (t * testing.T ) {
47+ should := require .New (t )
48+ var nilMap map [string ]string
49+ output , err := jsoniter .MarshalToString (nilMap )
50+ should .NoError (err )
51+ should .Equal (`null` , output )
52+ }
Original file line number Diff line number Diff line change @@ -249,6 +249,10 @@ type mapEncoder struct {
249249}
250250
251251func (encoder * mapEncoder ) Encode (ptr unsafe.Pointer , stream * Stream ) {
252+ if * (* unsafe .Pointer )(ptr ) == nil {
253+ stream .WriteNil ()
254+ return
255+ }
252256 stream .WriteObjectStart ()
253257 iter := encoder .mapType .UnsafeIterate (ptr )
254258 for i := 0 ; iter .HasNext (); i ++ {
You can’t perform that action at this time.
0 commit comments