-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Related to #56 - but it seems like the fix has had a regression since then? I can't find the unit test that was included as part of the fix either.
jsoniter marshals a nil map as {} instead of null. Empty maps are correctly marshalled as {}. This also affects nil maps inside structs.
var nilMap map[string]string
data, _ := jsoniter.Marshal(nilMap)
fmt.Printf("%s\n", string(data))
// {}Interestingly, if you enable SortMapKeys, the problem goes away, but I don't want the performance cost of sorting the map keys just to fix this issue.
I have an example below showing the difference between encoding/json, the default jsoniter config, and a SortMapKeys:true config:
https://play.golang.org/p/bMKiBk1wptz
Which produces this result:
encoding/json: null
jsoniter default: {}
jsoniter sortMapKeys: null
Metadata
Metadata
Assignees
Labels
No labels